// 导入库
var project = require('./project.json');
var storage = storages.create("autotouchShijieXy");

// 开发配置
var isPulic = true;
var lmNontinue = 16; // 跳过联盟打野中心点
// 固定数据
var gamePackageName = "com.qqgame.mic";
var gameActivity = "com.qqgame.mic.YXSMainActivity";
var floatyConsole = null; // 日志悬浮窗
var secureNum = 5; // 容错次数 避免死循环
// 修改数据
var myLogStr = ""; // 重写打印
var zhuchengbeihui = false; // 主城被毁
var dixiTishi = true; // 敌袭提示
var shouyejinru = false; // 是不是从游戏首页进入
var xiaobingbuzu = false; // 小兵不足
var caijiduiwu = 0; // 采集队伍
var caijileixingYx = 0; // 优先采集种类
var dayeduiwu = 0; // 打野队伍
var picJizhun = 1;
var picJizhunHeight = 1;
var deviceWidth = device.width;
var deviceHeight = device.height;
var allDateStr = "";
var zuiduancaiji = 0;
var duiwushangxian = Boolean(storage.get("tianxuan", true)) ? 3 : 2;
var otherQqAccount = storage.get("otherQqAccount", ""); // 必须qq 如果不是空 选定指定账号进行账号切换
var youshangDuilie = { x: device.height - 880, y: 159, w: 880, h: 80 };
var youshangZiyuan = { x: device.height - 1000, y: 1, w: 600, h: 80 };
log('宽高:', deviceWidth, deviceHeight)

// 缓存数据
var delayBase = 1;
var yanchi = 500; // 点击后停顿
var yanchi1 = 1000; // 点击前停顿
var yanchi2 = 2000; // 点击后停顿
var yanchi3 = 3000; // 点击后停顿
var yanchi5 = 5000; // 点击后停顿

var shibiefangshi = parseInt(storage.get("shibiefangshi", 0)); // 识别方式选择
var shangciweizhi = storage.get("shangciweizhi", { x: 0, y: 0 }); // 上次位置坐标
var xiaodituPosit = storage.get("xiaodituPosit", { x: 0, y: 0 }); // 小地图起始位置
var yuanbaoweizhi = storage.get("yuanbaoweizhi", { x: 2020, y: 0 }); // 元宝位置
var xiaohaochihou = storage.get("xiaohaochihou", { x: 0, y: 0, w: 300, h: 65 }); // 元宝位置
var zhandouliWeizhi = storage.get("zhandouliPosit", { x: 0, y: 0, w: 500, h: 65 }); // 战斗力起始位置
var cunliangWeizhi = storage.get("cunliangWeizhi", { x: 0, y: 0, w: 260, h: 45 }); // 存量起始位置
var yingxiongMsgWeizhi = storage.get("yingxiongMsgWeizhi", { x: 0, y: 0, w: 300, h: 0 }); // 英雄信息坐标
var ziyuanZuobianWeizhi = storage.get("ziyuanZuobianWeizhi", { x: 0, y: 0, w: 300, h: 65 }); // 资源信息坐标 
var toCaijiList = storage.get("caijiItems", [{ x: 66, y: 66, level: 1, type: 2 }, { x: 88, y: 88, level: 2, type: 1 }]); // 资源列表 坐标 等级 类型 粮木矿-123

// 联盟区域
// 93 61
var zuoshangList = [{ "x": 90, "y": 64 }, { "x": 80, "y": 64 }, { "x": 80, "y": 56 }, { "x": 90, "y": 56 }, { "x": 100, "y": 56 }, { "x": 100, "y": 64 }, { "x": 100, "y": 72 }, { "x": 90, "y": 72 }, { "x": 80, "y": 72 }, { "x": 70, "y": 64 }, { "x": 70, "y": 56 }, { "x": 70, "y": 48 }, { "x": 80, "y": 48 }, { "x": 90, "y": 48 }, { "x": 100, "y": 48 }, { "x": 110, "y": 48 }, { "x": 110, "y": 56 }, { "x": 110, "y": 64 }, { "x": 110, "y": 72 }, { "x": 110, "y": 80 }, { "x": 100, "y": 80 }, { "x": 90, "y": 80 }, { "x": 80, "y": 80 }, { "x": 70, "y": 80 }, { "x": 70, "y": 72 }, { "x": 60, "y": 64 }, { "x": 60, "y": 56 }, { "x": 60, "y": 48 }, { "x": 60, "y": 40 }, { "x": 70, "y": 40 }, { "x": 80, "y": 40 }, { "x": 90, "y": 40 }, { "x": 100, "y": 40 }, { "x": 110, "y": 40 }, { "x": 120, "y": 40 }, { "x": 120, "y": 48 }, { "x": 120, "y": 56 }, { "x": 120, "y": 64 }, { "x": 120, "y": 72 }, { "x": 120, "y": 80 }, { "x": 120, "y": 88 }, { "x": 110, "y": 88 }, { "x": 100, "y": 88 }, { "x": 90, "y": 88 }, { "x": 80, "y": 88 }, { "x": 60, "y": 72 }, { "x": 50, "y": 64 }, { "x": 50, "y": 56 }, { "x": 50, "y": 48 }, { "x": 50, "y": 40 }, { "x": 60, "y": 32 }, { "x": 70, "y": 32 }, { "x": 80, "y": 32 }, { "x": 90, "y": 32 }, { "x": 100, "y": 32 }, { "x": 110, "y": 32 }, { "x": 120, "y": 32 }, { "x": 120, "y": 96 }, { "x": 110, "y": 96 }, { "x": 100, "y": 96 }, { "x": 90, "y": 96 }]
// 62 124
var zuozhongList = [{ "x": 70, "y": 128 }, { "x": 60, "y": 128 }, { "x": 60, "y": 120 }, { "x": 70, "y": 120 }, { "x": 80, "y": 120 }, { "x": 80, "y": 128 }, { "x": 80, "y": 136 }, { "x": 70, "y": 136 }, { "x": 60, "y": 136 }, { "x": 50, "y": 128 }, { "x": 50, "y": 120 }, { "x": 50, "y": 112 }, { "x": 60, "y": 112 }, { "x": 70, "y": 112 }, { "x": 80, "y": 112 }, { "x": 90, "y": 112 }, { "x": 90, "y": 120 }, { "x": 90, "y": 128 }, { "x": 90, "y": 136 }, { "x": 90, "y": 144 }, { "x": 80, "y": 144 }, { "x": 70, "y": 144 }, { "x": 60, "y": 144 }, { "x": 50, "y": 144 }, { "x": 50, "y": 136 }, { "x": 40, "y": 128 }, { "x": 40, "y": 120 }, { "x": 40, "y": 112 }, { "x": 40, "y": 104 }, { "x": 50, "y": 104 }, { "x": 60, "y": 104 }, { "x": 70, "y": 104 }, { "x": 80, "y": 104 }, { "x": 90, "y": 104 }, { "x": 100, "y": 112 }, { "x": 100, "y": 120 }, { "x": 100, "y": 128 }, { "x": 100, "y": 136 }, { "x": 80, "y": 152 }, { "x": 70, "y": 152 }, { "x": 60, "y": 152 }, { "x": 50, "y": 152 }, { "x": 40, "y": 152 }, { "x": 40, "y": 144 }, { "x": 40, "y": 136 }, { "x": 40, "y": 96 }, { "x": 50, "y": 96 }, { "x": 60, "y": 96 }, { "x": 70, "y": 96 }, { "x": 80, "y": 96 }, { "x": 110, "y": 112 }, { "x": 110, "y": 120 }, { "x": 110, "y": 128 }, { "x": 110, "y": 136 }, { "x": 70, "y": 160 }, { "x": 60, "y": 160 }, { "x": 50, "y": 160 }, { "x": 40, "y": 160 }, { "x": 40, "y": 88 }, { "x": 50, "y": 88 }, { "x": 60, "y": 88 }, { "x": 70, "y": 88 }, { "x": 50, "y": 168 }, { "x": 40, "y": 168 }, { "x": 40, "y": 80 }, { "x": 50, "y": 80 }, { "x": 60, "y": 80 }, { "x": 40, "y": 72 }, { "x": 50, "y": 72 }]
// 84 187
var zuoxiaList = [{ "x": 90, "y": 192 }, { "x": 80, "y": 192 }, { "x": 80, "y": 184 }, { "x": 90, "y": 184 }, { "x": 100, "y": 184 }, { "x": 100, "y": 192 }, { "x": 100, "y": 200 }, { "x": 90, "y": 200 }, { "x": 80, "y": 200 }, { "x": 70, "y": 192 }, { "x": 70, "y": 184 }, { "x": 70, "y": 176 }, { "x": 80, "y": 176 }, { "x": 90, "y": 176 }, { "x": 100, "y": 176 }, { "x": 110, "y": 176 }, { "x": 110, "y": 184 }, { "x": 110, "y": 192 }, { "x": 110, "y": 200 }, { "x": 110, "y": 208 }, { "x": 100, "y": 208 }, { "x": 90, "y": 208 }, { "x": 80, "y": 208 }, { "x": 70, "y": 208 }, { "x": 70, "y": 200 }, { "x": 60, "y": 192 }, { "x": 60, "y": 184 }, { "x": 60, "y": 176 }, { "x": 60, "y": 168 }, { "x": 70, "y": 168 }, { "x": 80, "y": 168 }, { "x": 90, "y": 168 }, { "x": 100, "y": 168 }, { "x": 110, "y": 168 }, { "x": 120, "y": 168 }, { "x": 120, "y": 176 }, { "x": 120, "y": 184 }, { "x": 120, "y": 192 }, { "x": 120, "y": 200 }, { "x": 120, "y": 208 }, { "x": 120, "y": 216 }, { "x": 110, "y": 216 }, { "x": 100, "y": 216 }, { "x": 90, "y": 216 }, { "x": 80, "y": 216 }, { "x": 70, "y": 216 }, { "x": 60, "y": 208 }, { "x": 60, "y": 200 }, { "x": 50, "y": 192 }, { "x": 50, "y": 184 }, { "x": 50, "y": 176 }, { "x": 70, "y": 160 }, { "x": 80, "y": 160 }, { "x": 90, "y": 160 }, { "x": 100, "y": 160 }, { "x": 110, "y": 160 }, { "x": 120, "y": 160 }, { "x": 120, "y": 224 }, { "x": 110, "y": 224 }, { "x": 100, "y": 224 }, { "x": 90, "y": 224 }, { "x": 80, "y": 224 }, { "x": 50, "y": 200 }, { "x": 80, "y": 152 }, { "x": 90, "y": 152 }, { "x": 100, "y": 152 }, { "x": 110, "y": 152 }, { "x": 120, "y": 152 }, { "x": 90, "y": 144 }, { "x": 100, "y": 144 }, { "x": 110, "y": 144 }, { "x": 120, "y": 144 }, { "x": 100, "y": 136 }, { "x": 110, "y": 136 }]
// 165.61
var youshangList = [{ "x": 170, "y": 64 }, { "x": 160, "y": 64 }, { "x": 160, "y": 56 }, { "x": 170, "y": 56 }, { "x": 180, "y": 56 }, { "x": 180, "y": 64 }, { "x": 180, "y": 72 }, { "x": 170, "y": 72 }, { "x": 160, "y": 72 }, { "x": 150, "y": 64 }, { "x": 150, "y": 56 }, { "x": 150, "y": 48 }, { "x": 160, "y": 48 }, { "x": 170, "y": 48 }, { "x": 180, "y": 48 }, { "x": 190, "y": 48 }, { "x": 190, "y": 56 }, { "x": 190, "y": 64 }, { "x": 190, "y": 72 }, { "x": 180, "y": 80 }, { "x": 170, "y": 80 }, { "x": 160, "y": 80 }, { "x": 150, "y": 80 }, { "x": 150, "y": 72 }, { "x": 140, "y": 64 }, { "x": 140, "y": 56 }, { "x": 140, "y": 48 }, { "x": 140, "y": 40 }, { "x": 150, "y": 40 }, { "x": 160, "y": 40 }, { "x": 170, "y": 40 }, { "x": 180, "y": 40 }, { "x": 190, "y": 40 }, { "x": 200, "y": 40 }, { "x": 200, "y": 48 }, { "x": 200, "y": 56 }, { "x": 200, "y": 64 }, { "x": 170, "y": 88 }, { "x": 160, "y": 88 }, { "x": 150, "y": 88 }, { "x": 140, "y": 88 }, { "x": 140, "y": 80 }, { "x": 140, "y": 72 }, { "x": 130, "y": 64 }, { "x": 130, "y": 56 }, { "x": 130, "y": 48 }, { "x": 130, "y": 40 }, { "x": 130, "y": 32 }, { "x": 140, "y": 32 }, { "x": 150, "y": 32 }, { "x": 160, "y": 32 }, { "x": 170, "y": 32 }, { "x": 180, "y": 32 }, { "x": 190, "y": 32 }, { "x": 200, "y": 32 }, { "x": 210, "y": 40 }, { "x": 210, "y": 48 }, { "x": 210, "y": 56 }, { "x": 160, "y": 96 }, { "x": 150, "y": 96 }, { "x": 140, "y": 96 }, { "x": 130, "y": 96 }, { "x": 130, "y": 88 }, { "x": 130, "y": 80 }, { "x": 130, "y": 72 }, { "x": 130, "y": 24 }, { "x": 140, "y": 24 }, { "x": 150, "y": 24 }, { "x": 160, "y": 24 }, { "x": 170, "y": 24 }, { "x": 180, "y": 24 }, { "x": 190, "y": 24 }, { "x": 150, "y": 104 }, { "x": 140, "y": 104 }, { "x": 130, "y": 104 }, { "x": 140, "y": 112 }, { "x": 130, "y": 112 }]
// // 188.124
var youzhongList = [{ "x": 190, "y": 128 }, { "x": 180, "y": 128 }, { "x": 180, "y": 120 }, { "x": 190, "y": 120 }, { "x": 200, "y": 120 }, { "x": 200, "y": 128 }, { "x": 200, "y": 136 }, { "x": 190, "y": 136 }, { "x": 180, "y": 136 }, { "x": 170, "y": 128 }, { "x": 170, "y": 120 }, { "x": 170, "y": 112 }, { "x": 180, "y": 112 }, { "x": 190, "y": 112 }, { "x": 200, "y": 112 }, { "x": 210, "y": 112 }, { "x": 210, "y": 120 }, { "x": 210, "y": 128 }, { "x": 210, "y": 136 }, { "x": 210, "y": 144 }, { "x": 200, "y": 144 }, { "x": 190, "y": 144 }, { "x": 180, "y": 144 }, { "x": 170, "y": 144 }, { "x": 170, "y": 136 }, { "x": 160, "y": 128 }, { "x": 160, "y": 120 }, { "x": 160, "y": 112 }, { "x": 160, "y": 104 }, { "x": 170, "y": 104 }, { "x": 180, "y": 104 }, { "x": 190, "y": 104 }, { "x": 200, "y": 104 }, { "x": 210, "y": 104 }, { "x": 220, "y": 104 }, { "x": 220, "y": 112 }, { "x": 220, "y": 120 }, { "x": 220, "y": 128 }, { "x": 220, "y": 136 }, { "x": 220, "y": 144 }, { "x": 220, "y": 152 }, { "x": 210, "y": 152 }, { "x": 200, "y": 152 }, { "x": 190, "y": 152 }, { "x": 180, "y": 152 }, { "x": 170, "y": 152 }, { "x": 160, "y": 144 }, { "x": 160, "y": 136 }, { "x": 150, "y": 128 }, { "x": 150, "y": 120 }, { "x": 150, "y": 112 }, { "x": 170, "y": 96 }, { "x": 180, "y": 96 }, { "x": 190, "y": 96 }, { "x": 200, "y": 96 }, { "x": 210, "y": 96 }, { "x": 220, "y": 96 }, { "x": 220, "y": 160 }, { "x": 210, "y": 160 }, { "x": 200, "y": 160 }, { "x": 190, "y": 160 }, { "x": 180, "y": 160 }, { "x": 150, "y": 136 }, { "x": 180, "y": 88 }, { "x": 190, "y": 88 }, { "x": 200, "y": 88 }, { "x": 210, "y": 88 }, { "x": 210, "y": 168 }, { "x": 200, "y": 168 }, { "x": 190, "y": 168 }, { "x": 190, "y": 80 }, { "x": 200, "y": 80 }, { "x": 200, "y": 176 }]
// // 156.187
var youxiaList = [{ "x": 160, "y": 192 }, { "x": 150, "y": 192 }, { "x": 150, "y": 184 }, { "x": 160, "y": 184 }, { "x": 170, "y": 184 }, { "x": 170, "y": 192 }, { "x": 170, "y": 200 }, { "x": 160, "y": 200 }, { "x": 150, "y": 200 }, { "x": 140, "y": 192 }, { "x": 140, "y": 184 }, { "x": 140, "y": 176 }, { "x": 150, "y": 176 }, { "x": 160, "y": 176 }, { "x": 170, "y": 176 }, { "x": 180, "y": 176 }, { "x": 180, "y": 184 }, { "x": 180, "y": 192 }, { "x": 180, "y": 200 }, { "x": 180, "y": 208 }, { "x": 170, "y": 208 }, { "x": 160, "y": 208 }, { "x": 150, "y": 208 }, { "x": 140, "y": 208 }, { "x": 140, "y": 200 }, { "x": 130, "y": 192 }, { "x": 130, "y": 184 }, { "x": 130, "y": 176 }, { "x": 130, "y": 168 }, { "x": 140, "y": 168 }, { "x": 150, "y": 168 }, { "x": 160, "y": 168 }, { "x": 170, "y": 168 }, { "x": 180, "y": 168 }, { "x": 190, "y": 168 }, { "x": 190, "y": 176 }, { "x": 190, "y": 184 }, { "x": 190, "y": 192 }, { "x": 190, "y": 200 }, { "x": 190, "y": 208 }, { "x": 180, "y": 216 }, { "x": 170, "y": 216 }, { "x": 160, "y": 216 }, { "x": 150, "y": 216 }, { "x": 140, "y": 216 }, { "x": 130, "y": 216 }, { "x": 130, "y": 208 }, { "x": 130, "y": 200 }, { "x": 130, "y": 160 }, { "x": 140, "y": 160 }, { "x": 150, "y": 160 }, { "x": 160, "y": 160 }, { "x": 170, "y": 160 }, { "x": 180, "y": 160 }, { "x": 200, "y": 176 }, { "x": 200, "y": 184 }, { "x": 200, "y": 192 }, { "x": 200, "y": 200 }, { "x": 170, "y": 224 }, { "x": 160, "y": 224 }, { "x": 150, "y": 224 }, { "x": 140, "y": 224 }, { "x": 130, "y": 224 }, { "x": 130, "y": 152 }, { "x": 140, "y": 152 }, { "x": 150, "y": 152 }, { "x": 160, "y": 152 }, { "x": 170, "y": 152 }, { "x": 130, "y": 144 }, { "x": 140, "y": 144 }, { "x": 150, "y": 144 }, { "x": 160, "y": 144 }, { "x": 140, "y": 136 }, { "x": 150, "y": 136 }]

// 系统函数
// 监听本脚本运行结束
events.on("exit", function () {
    log("监听本脚本运行结束")
    if (floatyConsole) {
        floatyConsole.close()
    }
    floaty.closeAll()
});
//监听 say 事件
events.on("say", function (words) {
    if (words) {
        floatyConsole.close();
        exit()
    }
});
// 滑动事件
function swipeRandom(qx, qy, zx, zy, time) {
    swipe(qx, qy, zx, zy, time)
}
// 我的打印
function myLogFunc() {
    log(arguments)
    myLogStr += '\n' + String(arguments[0])
    //对控件的操作需要在UI线程中执行
    ui.run(function () {
        floatyConsole.myLog.text(" " + myLogStr + " ");
    });
    let zanting = storage.get("zanting", false);
    while (zanting) {
        zanting = storage.get("zanting", false);
        sleep(2000)
    }
}
function myInfoFunc() {
    log('Info', arguments)
}
function myLookFunc() {
    log('Look', arguments)
}
// 邮件检测
function isEmailValid(email) {
    const emailRegex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
    return emailRegex.test(email);
}
// 前往指定坐标 483就是16 进阶2.82 需要算法支持各种分辨率
function goXyFunc(x, y) {
    myLogFunc('前往坐标点', x, y)
    x = Number(x)
    y = Number(y)
    let zhia = parseInt(x / 50) + 1;
    let jiaozheng = 3;
    if (x < 127) {
        jiaozheng = 2;
        //     zhia = zhia - 1;
    }
    let xx = (xiaodituPosit.x + jiaozheng) + ((x + zhia) * (2.754 * picJizhun))
    let yy = (xiaodituPosit.y + 0.5) + (y * (2.4 * picJizhunHeight))
    if (Boolean(storage.get("isSanguo", false))) {
        xx = (xiaodituPosit.x) + ((x) * (4.328 * picJizhun))
        yy = (xiaodituPosit.y) + (y * (3.652 * picJizhunHeight))
    }
    log('小地图屏幕点:', xx, yy)
    sleep(yanchi1)
    click(xx, yy)
    sleep(yanchi2)
}

// 设备基准
function initDataFunc() {
    // 延迟
    delayBase = Number(storage.get("delayBase", "1"));
    yanchi = 600 * delayBase; // 点击后停顿
    yanchi1 = 1200 * delayBase; // 点击前停顿
    yanchi2 = 2000 * delayBase; // 点击后停顿
    yanchi3 = 3000 * delayBase; // 点击后停顿
    yanchi5 = 5000 * delayBase; // 点击后停顿
    // 基准
    deviceWidth = device.width > device.height ? device.width : device.height;
    deviceHeight = device.height > device.width ? device.width : device.height;
    picJizhun = deviceHeight / 1080;
    picJizhunHeight = deviceHeight / 1080;
    if (deviceHeight == 720) {
        picJizhun = 0.666666666666667;
    }
    if (deviceHeight == 1200) {
        picJizhun = 1.12;
    }
    picJizhunHeight = picJizhun;

    if (deviceHeight == 1152) {
        picJizhun = 1.0658;
        picJizhunHeight = 1.04471;
    }

    let minH = 80 * picJizhun;
    if (minH < 65) {
        minH = 65
    }
    // 数据
    youshangDuilie = { x: deviceWidth - (880 * picJizhun), y: (159 * picJizhun), w: (880 * picJizhun), h: minH }
    youshangZiyuan = { x: deviceWidth - (1000 * picJizhun), y: 1, w: (600 * picJizhun), h: minH };
    allDateStr = storage.get("allDateStr", "");
    otherQqAccount = storage.get("otherQqAccount", "");
    duiwushangxian = Boolean(storage.get("tianxuan", true)) ? 3 : 2;
    shangciweizhi = storage.get("shangciweizhi", { x: 0, y: 0 }); // 上次位置坐标
    xiaodituPosit = storage.get("xiaodituPosit", { x: 0, y: 0 }); // 小地图起始位置
    yuanbaoweizhi = storage.get("yuanbaoweizhi", { x: 2020, y: 0 }); // 元宝位置
    xiaohaochihou = storage.get("xiaohaochihou", { x: 0, y: 0, w: 300, h: 65 }); // 元宝位置
    zhandouliWeizhi = storage.get("zhandouliPosit", { x: 0, y: 0, w: 500, h: 65 }); // 战斗力起始位置
    cunliangWeizhi = storage.get("cunliangWeizhi", { x: 0, y: 0, w: 260, h: 45 }); // 存量起始位置
    yingxiongMsgWeizhi = storage.get("yingxiongMsgWeizhi", { x: 0, y: 0, w: 300, h: 0 }); // 英雄信息坐标
    ziyuanZuobianWeizhi = storage.get("ziyuanZuobianWeizhi", { x: 0, y: 0, w: 300, h: 65 }); // 资源信息坐标 
    myInfoFunc('初始化数据完成')
}

// 重连
function chonglianFunc() {
    if (Boolean(storage.get("islingdidenglu", false))) {
        timeThreads = threads.start(function () {
            log('检测重新连接')
            let jin = true;
            let threadImgs = images.read("./res/重连.png");
            threadImgs = images.scale(threadImgs, picJizhun, picJizhunHeight);
            setInterval(function () {
                let threadP = findImage(captureScreen(), threadImgs, { threshold: 0.85 });
                if (threadP && jin) {
                    jin = false;
                    let timess = Number(storage.get("lingdidenglu", "20"))
                    myLogFunc(timess + "分钟后重连")
                    storage.put("zanting", true);
                    timess = timess * 60 * 1000;
                    sleep(timess)
                    click(threadP.x, threadP.y)
                    myLogFunc("已重连")
                    sleep(yanchi5)
                    storage.put("zanting", false);
                }
            }, 10000);
        });
    }
}

// 脚本自执行
mainFunc();
function mainFunc() {
    // 判断是否已经结束
    if (!Boolean(storage.get("correctEntry", true))) {
        myInfoFunc("非正常启动，即将关闭！")
        exit();
    }
    myInfoFunc("开始任务")
    // 检查无障碍服务是否已经启用，如果没有启用则跳转到无障碍服务启用界面，并等待无障碍服务启动；当无障碍服务启动后脚本会继续运行。
    auto.waitFor()
    // 输出日志窗口
    xuanfuLogFunc()
    // 配置初始化变量   
    initDataFunc();
    shouyejinru = false;

    if (Boolean(storage.get("firstRun", false))) {
        myInfoFunc("截图权限")
        //截图权限自动化安卓版本高于Android 9
        if (device.sdkInt > 27) {
            //等待截屏权限申请并同意
            threads.start(function () {
                if (device.brand == "HUAWEI") {
                    packageName('com.android.systemui').text('允许').waitFor();
                    sleep(yanchi)
                    text('允许').click();
                } else {
                    packageName('com.android.systemui').text('立即开始').waitFor();
                    sleep(yanchi)
                    text('立即开始').click();
                }
            });
        }
        sleep(yanchi)
        myInfoFunc("获取截图权限")
        //申请截屏权限
        if (!requestScreenCapture(true)) {
            toastLog("请求截图失败");
            exit()
        }
        storage.put("firstRun", false);
    }

    // 请求服务
    let req = http.postJson("http://123.60.43.199:8866/main/v1/auto/yxsXysjApp", {
        activationCode: storage.get("jihuoma", ""),
        aap: "yxsXysj",
        deviceWidth: device.width,
        deviceHeight: device.height,
        brand: device.brand,
        versionCode: project.versionCode,
        release: device.release,
        sdkInt: device.sdkInt,
        androidId: device.getAndroidId(),
        fingerprint: device.fingerprint,
        startTime: new Date().getTime()
    });
    let rJson = req.body.json();
    if (rJson.code != 200) {
        let message = rJson.message ? rJson.message : "服务异常请联系客服！";
        toastLog(message)
        sleep(2000)
        exit()
        sleep(2000)
    } else {
        myLogFunc("服务成功注册！")
    }

    // 重连
    chonglianFunc()
    sleep(yanchi)
    // 启动游戏
    let appPackName = currentPackage();
    myLogFunc("启动游戏", appPackName)
    if (appPackName != gamePackageName) {
        app.launchPackage(gamePackageName);
        myLogFunc("游戏启动中，请稍等...")
        sleep(5000)
        appPackName = currentPackage();
        if (appPackName == gamePackageName) {
            myLogFunc("游戏已打开，请稍等...")
        }
        if (isPulic) {
            sleep(15000)
        } else {
            sleep(1000)
        }
    } else {
        sleep(1000)
        myLogFunc("游戏正在运行");
    }
    // 算法提示
    if (shibiefangshi == 0) {
        myLogFunc("谷歌+百度算法");
    } else if (shibiefangshi == 1) {
        myLogFunc("百度算法");
    } else {
        myLogFunc("谷歌算法");
    }
    // 启动程序
    sleep(1000)
    // 主程序入口
    LoginFunc()
}

// 悬浮窗
function xuanfuLogFunc() {
    if (floatyConsole) {
        return;
    }
    floatyConsole = floaty.rawWindow(
        <frame gravity="left">
            <text id="myLog" text="日志" textColor="#ffffff" textSize="8sp" ellipsize="marquee" gravity="bottom" />
        </frame>
    );
    let w = 358 * picJizhun
    let h = 188 * picJizhun
    floatyConsole.setSize(w, h)
    floatyConsole.setPosition(5, device.width - h);
    floatyConsole.setTouchable(false)
    floatyConsole.myLog.text(" " + myLogStr + " ");
}

// 登陆流程
function LoginFunc() {
    myLogFunc('检测更新')
    sleep(yanchi2)
    let thisImgs = images.read("./res/jixuyouxi.png");
    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
    let seat = findImage(captureScreen(), thisImgs, { threshold: 0.8 });
    thisImgs.recycle();
    if (seat) {
        myLookFunc(seat)
        myLogFunc('继续游戏')
        sleep(yanchi)
        click(seat.x, seat.y + 5)
        myLogFunc('等待...')
        sleep(yanchi5)
    } else {
        myInfoFunc('无需更新')
    }

    sleep(yanchi1)
    // if (Boolean(storage.get("jaincedenglu", false))) {
    myLogFunc('开始登陆任务')
    let thisCaptureScreen = captureScreen();
    isLoginFunc(thisCaptureScreen).then(selectProtocol).then(loginMethodFunc).then(QqSelectAccount).then((data) => {
        sleep(yanchi2)
        myLogFunc('界面', gameActivity, currentActivity())
        let i = 0;
        while (gameActivity != currentActivity() && i < secureNum) {
            i++;
            sleep(yanchi1)
            myLogFunc('登陆中', gameActivity, currentActivity())

        }
        sleep(yanchi5)
        ShouyeFunc()
        myLogFunc('登陆流程Data', data)
    }).catch((error) => {
        myLogFunc('无需登录')
        myLogFunc(error)
        ShouyeFunc()
    })
    // } else {
    //     myLogFunc('不检测登录')
    //     ShouyeFunc()
    // }

}

function isLoginFunc(cap) {
    let thispromise = new Promise((res, rej) => {
        let thisImgs = images.read("./res/适龄提示.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let p = findImage(cap, thisImgs, { region: [(deviceWidth / 2), (deviceHeight / 2), (deviceWidth / 2), (deviceHeight / 2)], threshold: 0.8 });
        thisImgs.recycle();
        if (p) {
            myLogFunc('未登陆界面', p)
            res(cap)
        } else {
            rej("未在登陆流程中！")
        }
    })
    return thispromise;
}

function selectProtocol_loops() {
    myLogFunc('没有找到协议,重新查询')
    sleep(yanchi1)
    let thisImgs = images.read("./res/选定协议.png");
    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
    let p = findImage(captureScreen(), thisImgs, { region: [0, (deviceHeight / 2), (deviceWidth / 2), (deviceHeight / 2)], threshold: 0.85 });
    thisImgs.recycle();
    if (p) {
        myLogFunc('选定用户协议')
        sleep(yanchi1)
        click(p.x, p.y)
        sleep(yanchi)
    }
}

function selectProtocol(cap) {
    let thispromise = new Promise((res, rej) => {
        let thisImgs = images.read("./res/选定协议.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let p = findImage(captureScreen(), thisImgs, { region: [0, (deviceHeight / 2), (deviceWidth / 2), (deviceHeight / 2)], threshold: 0.85 });
        thisImgs.recycle();
        if (p) {
            myLogFunc('选定用户协议')
            sleep(yanchi1)
            click(p.x, p.y)
            sleep(yanchi)
        } else {
            selectProtocol_loops()
        }
        res(cap)
    })

    return thispromise;
}

function loginMethodFunc(cap) {
    let thispromise = new Promise((res, rej) => {
        let thisImgs;
        if (parseInt(storage.get("denglufangshi", 0)) == 0) {
            thisImgs = images.read("./res/zqq登陆_1106_865_1420_964.png");
        } else {
            thisImgs = images.read("./res/z微信登录_507_867_703_965.png");
        }
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let p = findImage(captureScreen(), thisImgs, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)], threshold: 0.8 });
        thisImgs.recycle();
        if (p) {
            myLogFunc('选择登陆方式')
            sleep(yanchi1)
            click(p.x, p.y)
            sleep(yanchi)
            res('登陆方式')
        } else {
            rej("查找登陆按钮异常！")
        }
    })

    return thispromise;
}

function QqSelectAccount() {
    let thispromise = new Promise((res, rej) => {
        if (parseInt(storage.get("denglufangshi", 0)) == 0) {
            id("a0t").waitFor()
            let qqThisName = id("a0t").findOne().text()
            myLogFunc('用户名: ' + qqThisName)
            if (otherQqAccount == '') {

            } else {
                if (Boolean(storage.get("otherQqLogin", false)) && storage.get("denglufangshi", 0) == 0) {
                    // 选定其他已登陆账号
                    id("asz").findOne().click()
                    sleep(yanchi1)
                    if (text(otherQqAccount).exists()) {
                        className("android.widget.TextView").text(otherQqAccount).findOne().parent().click()
                    } else {
                        myLogFunc("账号不存在")
                        myLogFunc("请调整到授权登陆页")
                        back();
                        id("fds").waitFor()
                    }
                } else {
                    log("登陆方式或没勾选")
                }

            }
            // 统一授权登陆流程
            sleep(yanchi1)
            id("fds").findOne().click() // QQ授权登录
            sleep(yanchi1)
            id("b7p").waitFor()
            id("b7p").findOne().click() // 完成QQ授权
            sleep(yanchi1)
            if (id("b7p").exists()) {
                id("b7p").findOne().click() // 可能二次确认
            }
            res('QQ登陆完成')
        } else {
            sleep(yanchi3)
            res('Wx登陆完成')
        }
    })

    return thispromise;
}

// 循环执行寻找主页 
function ShouyeFunc(bloo) {
    myLogFunc('首页流程')
    let thisCaptureScreen = captureScreen();
    if (bloo) {
        thisCaptureScreen = false;
        log('禁止传参cap')
    }
    isTrueShouye(thisCaptureScreen).then(closeXinshoufuli).then(closeXinshourenwu).then(closeMeiriqiandao).then(closeZhengzhan).then((data) => {
        myLogFunc('不在首页流程')
        myLogFunc('进入世界模式查询')
        ShijieShouyeFunc()
    }).catch((error) => {
        myLogFunc(error)
        if (error != '游戏首页') {
            sleep(yanchi1)
            ShouyeFunc(true)
        } else {
            sleep(yanchi3)
            let enter = true;
            while (enter) {
                let thisImgs = images.read("./res/黑底关闭.png");
                thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
                let p = findImage(captureScreen(), thisImgs, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), (deviceHeight / 2)], threshold: 0.71 });
                thisImgs.recycle();
                if (p) {
                    myLogFunc('关闭')
                    click(p.x + 5, p.y + 5);
                    sleep(yanchi3)
                } else {
                    enter = false;
                }
            }
            // 进入世界页面
            sleep(yanchi1)
            ShijieShouyeFunc()
        }
    })
}

// 主页流程
function isTrueShouye(cap) {
    let thispromise = new Promise((res, rej) => {
        let thisImgs = images.read("./res/首页挑战.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let p = cap ? findImage(cap, thisImgs, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), deviceHeight], threshold: 0.9 }) : findImage(captureScreen(), thisImgs, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), deviceHeight], threshold: 0.9 });
        thisImgs.recycle();
        if (p) {
            myLogFunc('在游戏首页')
            let y = p.y - (150 * picJizhun)
            click(p.x, y);
            sleep(yanchi2)
            shouyejinru = true;
            rej('游戏首页')
        } else {
            myLookFunc('没有 首页挑战')
            res(cap)
        }
    })

    return thispromise;
}


function closeXinshoufuli(cap) {
    let thispromise = new Promise((res, rej) => {
        let thisImgs = images.read("./res/新手福利关闭_8.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let p = cap ? findImage(cap, thisImgs) : findImage(captureScreen(), thisImgs);
        thisImgs.recycle();
        if (p) {
            myLogFunc('新手福利')
            click(p.x, p.y);
            sleep(yanchi)
            rej('执行 新手福利关闭')
        } else {
            myLookFunc('不是 新手福利')
            res(cap)
        }
    })

    return thispromise;
}

function closeXinshourenwu(cap) {
    let thispromise = new Promise((res, rej) => {
        let thisImgs = images.read("./res/新手任务关闭.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let p = cap ? findImage(cap, thisImgs) : findImage(captureScreen(), thisImgs);
        thisImgs.recycle();
        if (p) {
            myLogFunc('新手任务')
            click(p.x, p.y);
            sleep(yanchi)
            rej('执行 新手任务关闭')
        } else {
            myLookFunc('不是 新手任务')
            res(cap)
        }
    })

    return thispromise;
}

function closeMeiriqiandao(cap) {
    let thispromise = new Promise((res, rej) => {
        let thisImgs = images.read("./res/蓝底关闭.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let p = cap ? findImage(cap, thisImgs, { threshold: 0.9 }) : findImage(captureScreen(), thisImgs, { threshold: 0.9 });
        thisImgs.recycle();
        if (p) {
            myLogFunc('首页签到')
            click(p.x + 5, p.y + 5);
            sleep(yanchi)
            rej('执行 首页签到关闭')
        } else {
            myLookFunc('不是 签到页面')
            res(cap)
        }
    })

    return thispromise;
}

function closeZhengzhan(cap) {
    let thispromise = new Promise((res, rej) => {
        let thisImgs = images.read("./res/征战关闭按钮.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let p = cap ? findImage(cap, thisImgs) : findImage(captureScreen(), thisImgs);
        thisImgs.recycle();
        if (p) {
            myLogFunc('征战关闭')
            click(p.x, p.y);
            sleep(yanchi)
            rej('执行 征战关闭按钮')
        } else {
            myLookFunc('不是 征战页面')
            res(cap)
        }
    })

    return thispromise;
}

// 世界模式检测流程
function isTrueShijieShouye(cap) {
    let thispromise = new Promise((res, rej) => {
        let thisImgs = images.read("./res/世界首页.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let p = cap ? findImage(cap, thisImgs, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)], threshold: 0.84 }) : findImage(captureScreen(), thisImgs, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)], threshold: 0.84 });
        thisImgs.recycle();
        if (p) {
            if (shouyejinru) {
                log('从首页进入 检查我的主城')
                let thisImgs1 = images.read("./res/我的主城.png");
                thisImgs1 = images.scale(thisImgs1, picJizhun, picJizhunHeight)
                let p1 = cap ? findImage(cap, thisImgs1, { threshold: 0.8 }) : findImage(captureScreen(), thisImgs1, { threshold: 0.8 });
                thisImgs1.recycle();
                if (p1) {
                    sleep(yanchi)
                    rej('匹配了世界模式')
                } else {
                    log('没有 世界模式我的主城')
                    res(cap)
                }
            } else {
                sleep(yanchi)
                rej('匹配了世界模式')
            }
        } else {
            log('没有 世界模式首页进入')
            res(cap)
        }
    })

    return thispromise;
}


function closeLiulizhenbaoLan(cap) {
    return new Promise((res, rej) => {
        let thisImgs = images.read("./res/琉璃珍宝关闭_蓝.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let p = cap ? findImage(cap, thisImgs) : findImage(captureScreen(), thisImgs);
        thisImgs.recycle();
        if (p) {
            myLogFunc('琉璃珍宝_蓝')
            click(p.x, p.y);
            sleep(yanchi)
            rej('执行 蓝琉璃珍宝关闭')
        } else {
            log('没有 蓝琉璃珍宝')
            res(cap)
        }
    })
}

function closeLiulizhenbaoFen(cap) {
    let thispromise = new Promise((res, rej) => {
        let thisImgs = images.read("./res/琉璃珍宝关闭_粉.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let p = cap ? findImage(cap, thisImgs) : findImage(captureScreen(), thisImgs);
        thisImgs.recycle();
        if (p) {
            myLogFunc('琉璃珍宝_粉')
            click(p.x, p.y);
            sleep(yanchi)
            rej('执行 琉璃珍宝_粉')
        } else {
            log('没有 粉琉璃珍宝')
            res(cap)
        }
    })

    return thispromise;
}

function closeXiaoxiannv(cap) {
    let thispromise = new Promise((res, rej) => {
        let thisImgs = images.read("./res/小仙女关闭_8.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let p = cap ? findImage(cap, thisImgs) : findImage(captureScreen(), thisImgs);
        thisImgs.recycle();
        if (p) {
            myLogFunc('小仙女')
            click(p.x, p.y);
            sleep(yanchi)
            rej('执行 小仙女关闭_8')
        } else {
            log('没有 小仙女')
            res(cap)
        }
    })

    return thispromise;
}

function closeLaotoubaojian(cap) {
    let thispromise = new Promise((res, rej) => {
        let thisImgs = images.read("./res/宝鉴关闭.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let p = cap ? findImage(cap, thisImgs) : findImage(captureScreen(), thisImgs);
        thisImgs.recycle();
        if (p) {
            myLogFunc('宝鉴')
            click(p.x, p.y);
            sleep(yanchi)
            rej('执行 宝鉴关闭')
        } else {
            log('没有 玲珑宝鉴')
            res(cap)
        }
    })

    return thispromise;
}

// 琉璃珍宝i关闭
function closeLiulizhenbaoLv(cap) {
    let thispromise = new Promise((res, rej) => {
        let thisImgs = images.read("./res/琉璃珍宝关闭_绿.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let p = cap ? findImage(cap, thisImgs) : findImage(captureScreen(), thisImgs);
        thisImgs.recycle();
        if (p) {
            myLogFunc('琉璃珍宝_绿')
            click(p.x, p.y);
            sleep(yanchi)
            rej('执行 琉璃珍宝关闭')
        } else {
            log('没有 绿琉璃珍宝')
            res(cap)
        }
    })

    return thispromise;
}

// 单个小仙女 灯笼关闭
function closeXiaoxiannvHui(cap) {
    let thispromise = new Promise((res, rej) => {
        let thisImgs = images.read("./res/琉璃珍宝关闭_小仙女.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let p = cap ? findImage(cap, thisImgs) : findImage(captureScreen(), thisImgs);
        thisImgs.recycle();
        if (p) {
            myLogFunc('琉璃珍宝_小仙女')
            click(p.x, p.y);
            sleep(yanchi)
            rej('执行 琉璃珍宝关闭_小仙女关闭')
        } else {
            log('没有 琉璃珍宝_小仙女')
            res(cap)
        }
    })

    return thispromise;
}

// 主城被毁
function closezhuchengBeihui(cap) {
    let thispromise = new Promise((res, rej) => {
        let thisImgs = images.read("./res/主城被毁.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let p = cap ? findImage(cap, thisImgs, { threshold: 0.85 }) : findImage(captureScreen(), thisImgs, { threshold: 0.85 });
        thisImgs.recycle();
        if (p) {
            myLogFunc('主城被毁')
            click(p.x, p.y);
            zhuchengbeihui = true;
            sleep(yanchi3)
            rej('执行 主城被毁')
        } else {
            log('没有 主城被毁')
            res(cap)
        }
    })

    return thispromise;
}

function closeHuoyuerenwu(cap) {
    let thispromise = new Promise((res, rej) => {
        let thisImgs = images.read("./res/关闭任务.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let p = cap ? findImage(cap, thisImgs) : findImage(captureScreen(), thisImgs);
        thisImgs.recycle();
        if (p) {
            myLogFunc('活跃任务')
            click(p.x, p.y);
            sleep(yanchi)
            rej('执行 任务关闭')
        } else {
            log('没有 活跃任务')
            res(cap)
        }
    })

    return thispromise;
}

// 小精灵检测 - 所有异常弹窗
function xiaojinglingJc() {
    sleep(yanchi2)
    let thisCaptureScreen = captureScreen();
    let zhixing = false;
    if (!zhixing) {
        let thisImgs = images.read("./res/蓝底关闭.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let p = findImage(thisCaptureScreen, thisImgs, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), (deviceHeight / 2)] });
        thisImgs.recycle();
        if (p) {
            myLogFunc('通用关闭')
            click(p.x + 5, p.y + 5);
            zhixing = true;
            sleep(yanchi)
        }
    }
    if (!zhixing) {
        let thisImgs = images.read("./res/小仙女关闭_8.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let p = findImage(thisCaptureScreen, thisImgs, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), (deviceHeight / 2)] });
        thisImgs.recycle();
        if (p) {
            myLogFunc('通用小仙女')
            click(p.x, p.y);
            zhixing = true;
            sleep(yanchi)
        }
    }
    if (!zhixing) {
        let thisImgs = images.read("./res/天选关闭.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let p = findImage(thisCaptureScreen, thisImgs, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), (deviceHeight / 2)] });
        thisImgs.recycle();
        if (p) {
            myLogFunc('天选关闭')
            click(p.x, p.y);
            zhixing = true;
            sleep(yanchi)
        }
    }
    if (!zhixing) {
        let thisImgs = images.read("./res/关闭任务.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let p = findImage(thisCaptureScreen, thisImgs, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), (deviceHeight / 2)] });
        thisImgs.recycle();
        if (p) {
            myLogFunc('关闭任务')
            click(p.x, p.y);
            zhixing = true;
            sleep(yanchi)
        }
    }
    if (!zhixing) {
        let thisImgs = images.read("./res/琉璃珍宝关闭_小仙女.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let p = findImage(thisCaptureScreen, thisImgs, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), (deviceHeight / 2)] });
        thisImgs.recycle();
        if (p) {
            myLogFunc('琉璃珍宝关闭_小仙女')
            click(p.x, p.y);
            zhixing = true;
            sleep(yanchi)
        }
    }
    if (!zhixing) {
        let thisImgs = images.read("./res/琉璃珍宝关闭_绿.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let p = findImage(thisCaptureScreen, thisImgs, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), (deviceHeight / 2)] });
        thisImgs.recycle();
        if (p) {
            myLogFunc('琉璃珍宝关闭_绿')
            click(p.x, p.y);
            zhixing = true;
            sleep(yanchi)
        }
    }
    if (!zhixing) {
        let thisImgs = images.read("./res/琉璃珍宝关闭_蓝.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let p = findImage(thisCaptureScreen, thisImgs, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), (deviceHeight / 2)] });
        thisImgs.recycle();
        if (p) {
            myLogFunc('琉璃珍宝关闭_蓝')
            click(p.x, p.y);
            zhixing = true;
            sleep(yanchi)
        }
    }
    if (!zhixing) {
        let thisImgs = images.read("./res/琉璃珍宝关闭_粉.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let p = findImage(thisCaptureScreen, thisImgs, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), (deviceHeight / 2)] });
        thisImgs.recycle();
        if (p) {
            myLogFunc('琉璃珍宝关闭_粉')
            click(p.x, p.y);
            zhixing = true;
            sleep(yanchi)
        }
    }

    if (!zhixing) {
        let thisImgs = images.read("./res/确认.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let p = findImage(thisCaptureScreen, thisImgs);
        thisImgs.recycle();
        if (p) {
            myLogFunc('确认')
            click(p.x, p.y);
            zhixing = true;
            sleep(yanchi)
        }
    }

    if (!zhixing) {
        let thisImgs = images.read("./res/宝鉴关闭.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let p = findImage(thisCaptureScreen, thisImgs, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), (deviceHeight / 2)] });
        thisImgs.recycle();
        if (p) {
            myLogFunc('宝鉴关闭')
            click(p.x, p.y);
            zhixing = true;
            sleep(yanchi)
        }
    }

    if (!zhixing) {
        let thisImgs2 = images.read("./res/联盟资源关闭.png");
        thisImgs2 = images.scale(thisImgs2, picJizhun, picJizhunHeight)
        let p2 = findImage(thisCaptureScreen, thisImgs2, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), (deviceHeight / 2)] });
        thisImgs2.recycle();
        if (p2) {
            myLogFunc('联盟资源关闭')
            click(p2.x + 5, p2.y + 5)
            sleep(yanchi1)
        }
    }

    if (!zhixing) {
        let thisImgs = images.read("./res/主城被毁.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let p = findImage(thisCaptureScreen, thisImgs, { threshold: 0.85 });
        thisImgs.recycle();
        if (p) {
            myLogFunc('主城被毁')
            click(p.x, p.y);
            zhixing = true;
            sleep(yanchi)
        }
    }
    return zhixing;
}

// 循环执行寻找世界模式主页 
function ShijieShouyeFunc() {
    myLogFunc('世界模式流程')
    sleep(yanchi5)
    let thisCaptureScreen = captureScreen();
    isTrueShijieShouye(thisCaptureScreen).then(closeLiulizhenbaoLan).then(closeXiaoxiannv).then(closeLaotoubaojian).then(closeLiulizhenbaoLv).then(closeXiaoxiannvHui).then(closeHuoyuerenwu).then(closeLiulizhenbaoFen).then(closezhuchengBeihui).then((data) => {
        myLogFunc('世界模式查询失败')
        ShouyeFunc();
    }).catch((error) => {
        myLogFunc(error)
        if (error != '匹配了世界模式') {
            ShijieShouyeFunc()
        } else {
            // 进入世界流程
            myLogFunc("进入世界设定流程")
            sleep(yanchi2)
            // !!! 任务列表 !!!
            // 采集队列识别
            caijiduilieFunc()
            // 领取军报
            if (Boolean(storage.get("junbao", false))) {
                lqjunbaoFunc()
                xiaojinglingJc()
            }
            // 高频检测敌袭
            if (Boolean(storage.get("dixigaopinJc", false)) && dixiTishi) {
                dixiJianceFunc()
            }
            // 自动征收
            if (Boolean(storage.get("tianxuan", false))) {
                if (Boolean(storage.get("zhengshou", false))) {
                    zhengshouFunc()
                    xiaojinglingJc()
                }
            }
            // 高频检测敌袭
            if (Boolean(storage.get("dixigaopinJc", false)) && dixiTishi) {
                dixiJianceFunc()
            }
            // 领取任务
            if (Boolean(storage.get("lingqurenwu", false))) {
                lingqurenwuFunc()
                xiaojinglingJc()
            } else {
                seeTimerenwuFunc()
                xiaojinglingJc()
            }
            // 高频检测敌袭
            if (Boolean(storage.get("dixigaopinJc", false)) && dixiTishi) {
                dixiJianceFunc()
            }
            // 如果主城被毁
            if (Boolean(storage.get("zidongxiucheng", false))) {
                // 返回自己主城
                fanhuizhuchengFunc();
                sleep(1000)
                zhuchengXiuchengFunc()
            }
            // 高频检测敌袭
            if (Boolean(storage.get("dixigaopinJc", false)) && dixiTishi) {
                dixiJianceFunc()
            }
            // 仓库取资源
            if (Boolean(storage.get("quziyuan", false))) {
                cangkuquziyuan()
            }
            // 高频检测敌袭
            if (Boolean(storage.get("dixigaopinJc", false)) && dixiTishi) {
                dixiJianceFunc()
            }
            // 每日任务 免费招募
            let thisDateStr = new Date().toDateString()
            log('allDateStr', allDateStr, allDateStr.indexOf(thisDateStr))
            if (Boolean(storage.get("mianfeizhaomu", false)) && allDateStr.indexOf(thisDateStr) == -1) {
                // 返回自己主城
                fanhuizhuchengFunc();
                sleep(1000)
                mianfeizhaomuFunc();
            }
            // 高频检测敌袭
            if (Boolean(storage.get("dixigaopinJc", false)) && dixiTishi) {
                dixiJianceFunc()
            }
            // 升级建筑
            if (Boolean(storage.get("sjShengjia", false))) {
                // 返回自己主城
                fanhuizhuchengFunc();
                sleep(1000)
                shengjijianzhuFunc();
            }
            // 高频检测敌袭
            if (Boolean(storage.get("dixigaopinJc", false)) && dixiTishi) {
                dixiJianceFunc()
            }
            // 训练士兵
            if (Boolean(storage.get("xunliansb", false))) {
                // 返回自己主城
                fanhuizhuchengFunc();
                sleep(1000)
                xunlianshibingFunc();
            }
            // 高频检测敌袭
            if (Boolean(storage.get("dixigaopinJc", false)) && dixiTishi) {
                dixiJianceFunc()
            }
            // 联盟捐赠
            if (Boolean(storage.get("lianmengjuanzeng", false))) {
                // 返回自己主城
                fanhuizhuchengFunc();
                sleep(1000)
                lianmengjuanzengFunc();
            }
            // 高频检测敌袭
            if (Boolean(storage.get("dixigaopinJc", false)) && dixiTishi) {
                dixiJianceFunc()
            }

            // 联盟互助
            if (Boolean(storage.get("lianmenghuzhu", false))) {
                // 返回自己主城
                fanhuizhuchengFunc();
                sleep(1000)
                lianmenghuzhuFunc();
            }
            // 高频检测敌袭
            if (Boolean(storage.get("dixigaopinJc", false)) && dixiTishi) {
                dixiJianceFunc()
            }
            // 采集任务
            if (Boolean(storage.get("caijiziyuan", true))) {
                caijiziyuanFunc()
                zuiduancaiji = zuiduancaijiFunc()
            }
            // 灵台任务
            if (Boolean(storage.get("lingtai", false))) {

            }
            // 扫描联盟范围
            if (Boolean(storage.get("isdaye", false))) {
                saomiaodayeFunc()
            }

            // 返回自己主城
            fanhuizhuchengFunc();

            // 结束运行后如何安排
            if (parseInt(storage.get("yunxingfangshi", 1)) == 0) {
                myLogFunc('设置-智能运行')
                let clipRestart = images.clip(captureScreen(), youshangDuilie.x, youshangDuilie.y, youshangDuilie.w, youshangDuilie.h);
                let paddleOcrRestart = paddle.ocr(clipRestart);
                clipRestart.recycle();
                let restartTime = 0;
                for (let index = 0; index < paddleOcrRestart.length; index++) {
                    let element = paddleOcrRestart[index];
                    if (element.text.includes(':')) {
                        log("paddleOcrRestart", element)
                        let shortest = formatGameTime(element.text);
                        if (restartTime == 0) {
                            restartTime = shortest;
                            log('restartTime', restartTime)
                        }
                        if (shortest < restartTime && shortest != 0) {
                            myLogFunc('较短时间:' + element.text)
                            restartTime = shortest;
                        }
                    }
                }
                let restartTimeFen = parseInt(restartTime / 1000 / 60)
                if (restartTimeFen == 0) {
                    myLogFunc('一分钟后重新运行！')
                } else {
                    myLogFunc('最短时间:' + restartTimeFen + '分钟！')
                }
                sleep(2500)
                // 小于十分钟 采集任务
                let runAgainTime = restartTime + (1000 * 120)
                if (restartTimeFen < 12) {
                    myLogFunc('等待较短采集任务！')
                    let reloadTimeOut = setTimeout(() => {
                        // 重新运行
                        ShijieShouyeFunc()
                        clearTimeout(reloadTimeOut)
                    }, runAgainTime);
                } else {
                    // 出野怪时间配置
                    if (Boolean(storage.get("isdaye", false))) {
                        let timeArr = [3, 6, 9, 12, 15, 18, 24]
                        let thisTime = new Date()
                        let getHours = thisTime.getHours()
                        let getMinutes = thisTime.getMinutes()
                        log(getHours)
                        log(getMinutes)
                        let selectTime = 0;
                        for (let index = 0; index < timeArr.length; index++) {
                            let element = timeArr[index];
                            if (selectTime == 0 && (element - getHours) > 0) {
                                selectTime = element
                            }
                        }
                        log(selectTime)
                        selectTime = (selectTime - getHours) * 60 - getMinutes;
                        log(selectTime)
                        if (restartTimeFen > selectTime) {
                            myLogFunc('智能野怪刷新时重启')
                            restartTimeFen = selectTime - 6;
                            restartTime = restartTimeFen * 1000 * 60
                        }
                    }

                    // 长时间采集任务
                    if (restartTimeFen > 90) {
                        myLogFunc('智能时间限制')
                        restartTimeFen = 90
                        restartTime = restartTimeFen * 1000 * 60
                    }
                    myLogFunc((restartTimeFen + 6) + '分钟后重新运行！')
                    sleep(yanchi1)
                    myLogFunc('本次运行即将结束')
                    sleep(yanchi1)
                    caijiduiwu = 0;
                    sleep(yanchi1)
                    runAgainTime = restartTime + (1000 * 360)
                    var reloadInterval1 = 0;
                    if (Boolean(storage.get("zhenjibaohuo", false))) {
                        reloadInterval1 = setInterval(() => {
                            toastLog(' 保活')
                            myLogFunc('保活')
                        }, 1000 * 60 * 5)
                    }
                    myLogFunc('智能运行，挂机等待')
                    sleep(runAgainTime)
                    myLogStr = "";
                    floatyConsole.close()
                    if (Boolean(storage.get("zhenjibaohuo", false))) {
                        clearInterval(reloadInterval1)
                    }
                }
                toastLog('智能运行 启动新任务')
                threads.shutDownAll()
                sleep(yanchi2)
            } else if (parseInt(storage.get("yunxingfangshi", 1)) == 1) {
                myLogFunc('设置-循环运行')
                myLogFunc('一分钟后循环运行')
                sleep(60000)
                myLogStr = "";
                floatyConsole.close()
                toastLog('循环运行 启动新任务')
                threads.shutDownAll()
                sleep(yanchi2)
            } else if (parseInt(storage.get("yunxingfangshi", 1)) == 2) {
                myLogFunc('设置-定时运行')
                let intermission = Number(storage.get("intermission", "1"))
                intermission = intermission * 60 * 1000;
                caijiduiwu = 0;
                var reloadInterval2 = 0;
                if (Boolean(storage.get("zhenjibaohuo", false))) {
                    reloadInterval2 = setInterval(() => {
                        toastLog(' 保活')
                        myLogFunc('保活')
                    }, 1000 * 60 * 9)
                }
                myLogFunc('定时运行，' + intermission + '小时后启动')
                sleep(intermission)
                myLogStr = "";
                floatyConsole.close()
                if (Boolean(storage.get("zhenjibaohuo", false))) {
                    clearInterval(reloadInterval2)
                }
                toastLog('定时运行 启动新任务')
                threads.shutDownAll()
                sleep(yanchi2)
            }
            // 结束
        }
    })
}

// 主城被毁灭
function zhuchengXiuchengFunc() {
    let thisImgs1 = images.read("./res/我的主城.png");
    thisImgs1 = images.scale(thisImgs1, picJizhun, picJizhunHeight)
    let p1 = findImage(captureScreen(), thisImgs1, { region: [(deviceWidth / 4), 150, (deviceWidth / 2), (deviceHeight - 200)], threshold: 0.8 });
    thisImgs1.recycle();
    if (p1) {
        myLogFunc("我的主城")
        click(p1.x, p1.y - 80)
        sleep(yanchi2)
        let thisImgs2 = images.read("./res/城防.png");
        thisImgs2 = images.scale(thisImgs2, picJizhun, picJizhunHeight)
        let p2 = findImage(captureScreen(), thisImgs2, { threshold: 0.86 });
        thisImgs2.recycle();
        if (p2) {
            myLogFunc("城防")
            click(p2.x, p2.y)
            sleep(yanchi2)

            let thisImgs3 = images.read("./res/修理.png");
            thisImgs3 = images.scale(thisImgs3, picJizhun, picJizhunHeight)
            let p3 = findImage(captureScreen(), thisImgs3, { threshold: 0.86 });
            thisImgs3.recycle();
            if (p3) {
                myLogFunc("修理")
                click(p3.x, p3.y)
                sleep(yanchi2)
                let thisImgs4 = images.read("./res/修理1.png");
                thisImgs4 = images.scale(thisImgs4, picJizhun, picJizhunHeight)
                let p4 = findImage(captureScreen(), thisImgs4, { threshold: 0.86 });
                thisImgs4.recycle();
                if (p4) {
                    myLogFunc("进行修理")
                    click(p4.x, p4.y)
                    sleep(yanchi2)
                } else {
                    myLogFunc("材料不足")
                }
            }
        } else {
            myLogFunc("点击主城城防异常")
        }

        let enter = true;
        while (enter) {
            let thisImgs = images.read("./res/黑底关闭.png");
            thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
            let p = findImage(captureScreen(), thisImgs, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), (deviceHeight / 2)], threshold: 0.86 });
            thisImgs.recycle();
            if (p) {
                myLogFunc('关闭')
                click(p.x + 5, p.y + 5);
                sleep(yanchi1)
            } else {
                enter = false;
                sleep(yanchi)
            }
        }
    }
}

// 升级建筑
// 升级建筑
function shengjijianzhuFunc() {
    let cishu = 0;
    let thisImgs1 = images.read("./res/我的主城.png");
    thisImgs1 = images.scale(thisImgs1, picJizhun, picJizhunHeight)
    let p1 = findImage(captureScreen(), thisImgs1, { region: [(deviceWidth / 4), 150, (deviceWidth / 2), (deviceHeight - 200)], threshold: 0.8 });
    thisImgs1.recycle();
    if (p1) {
        myLogFunc("我的主城")
        click(p1.x, p1.y - 80)
        sleep(yanchi2)
        if (Boolean(storage.get("sjShengjia", false))) {
            let thisImgs3 = images.read("./res/升级1.png");
            thisImgs3 = images.scale(thisImgs3, picJizhun, picJizhunHeight)
            let p3 = findImage(captureScreen(), thisImgs3, { threshold: 0.86 });
            thisImgs3.recycle();
            if (p3) {
                log("升级1")
                click(p3.x, p3.y)
                sleep(yanchi1)
                let thisImgs4 = images.read("./res/升级2.png");
                thisImgs4 = images.scale(thisImgs4, picJizhun, picJizhunHeight)
                let p4 = findImage(captureScreen(), thisImgs4, { threshold: 0.86 });
                thisImgs4.recycle();
                if (p4) {
                    log("升级2")
                    cishu += 1;
                    click(p4.x, p4.y)
                    sleep(yanchi)
                    back()
                    sleep(yanchi1)
                } else {
                    let thisImgs = images.read("./res/黑底关闭.png");
                    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
                    let p = findImage(captureScreen(), thisImgs, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), (deviceHeight / 2)], threshold: 0.86 });
                    thisImgs.recycle();
                    if (p) {
                        myLogFunc('关闭')
                        click(p.x + 5, p.y + 5);
                        sleep(yanchi1)
                    }
                }
            } else {
                let thisImgs = images.read("./res/黑底关闭.png");
                thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
                let p = findImage(captureScreen(), thisImgs, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), (deviceHeight / 2)], threshold: 0.86 });
                thisImgs.recycle();
                if (p) {
                    myLogFunc('关闭')
                    click(p.x + 5, p.y + 5);
                    sleep(yanchi1)
                }
            }
        }

        if (Boolean(storage.get("sjYingxiong", false)) && cishu < duiwushangxian) {
            let thisImgs2 = images.read("./res/英雄府.png");
            thisImgs2 = images.scale(thisImgs2, picJizhun, picJizhunHeight)
            let p2 = findImage(captureScreen(), thisImgs2, { threshold: 0.82 });
            thisImgs2.recycle();
            if (p2) {
                myLogFunc("英雄府")
                click(p2.x, p2.y)
                sleep(yanchi2)
                let thisImgs3 = images.read("./res/升级1.png");
                thisImgs3 = images.scale(thisImgs3, picJizhun, picJizhunHeight)
                let p3 = findImage(captureScreen(), thisImgs3, { threshold: 0.86 });
                thisImgs3.recycle();
                if (p3) {
                    click(p3.x, p3.y)
                    sleep(yanchi1)
                    let thisImgs4 = images.read("./res/升级2.png");
                    thisImgs4 = images.scale(thisImgs4, picJizhun, picJizhunHeight)
                    let p4 = findImage(captureScreen(), thisImgs4, { threshold: 0.86 });
                    thisImgs4.recycle();
                    if (p4) {
                        cishu += 1;
                        click(p4.x, p4.y)
                        sleep(yanchi)
                        back()
                        sleep(yanchi1)
                    } else {
                        let enterNum = 2;
                        while (enterNum > 0) {
                            let thisImgs = images.read("./res/黑底关闭.png");
                            thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
                            let p = findImage(captureScreen(), thisImgs, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), (deviceHeight / 2)], threshold: 0.86 });
                            thisImgs.recycle();
                            if (p) {
                                myLogFunc('关闭')
                                click(p.x + 5, p.y + 5);
                                enterNum -= 1;
                                sleep(yanchi1)
                            } else {
                                enterNum = -1;
                            }
                        }
                    }
                } else {
                    let thisImgs = images.read("./res/黑底关闭.png");
                    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
                    let p = findImage(captureScreen(), thisImgs, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), (deviceHeight / 2)], threshold: 0.86 });
                    thisImgs.recycle();
                    if (p) {
                        myLogFunc('关闭')
                        click(p.x + 5, p.y + 5);
                        sleep(yanchi1)
                    }
                }
            } else {
                myLogFunc("升级主城酒馆异常")
            }
        }
        if (Boolean(storage.get("sjBingying", false)) && cishu < duiwushangxian) {
            let thisImgs2 = images.read("./res/兵营.png");
            thisImgs2 = images.scale(thisImgs2, picJizhun, picJizhunHeight)
            let p2 = findImage(captureScreen(), thisImgs2, { threshold: 0.82 });
            thisImgs2.recycle();
            if (p2) {
                myLogFunc("兵营")
                click(p2.x, p2.y)
                sleep(yanchi2)
                let thisImgs3 = images.read("./res/升级1.png");
                thisImgs3 = images.scale(thisImgs3, picJizhun, picJizhunHeight)
                let p3 = findImage(captureScreen(), thisImgs3, { threshold: 0.86 });
                thisImgs3.recycle();
                if (p3) {
                    click(p3.x, p3.y)
                    sleep(yanchi1)
                    let thisImgs4 = images.read("./res/升级2.png");
                    thisImgs4 = images.scale(thisImgs4, picJizhun, picJizhunHeight)
                    let p4 = findImage(captureScreen(), thisImgs4, { threshold: 0.86 });
                    thisImgs4.recycle();
                    if (p4) {
                        cishu += 1;
                        click(p4.x, p4.y)
                        sleep(yanchi)
                        back()
                        sleep(yanchi1)
                    } else {
                        let enterNum = 2;
                        while (enterNum > 0) {
                            let thisImgs = images.read("./res/黑底关闭.png");
                            thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
                            let p = findImage(captureScreen(), thisImgs, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), (deviceHeight / 2)], threshold: 0.86 });
                            thisImgs.recycle();
                            if (p) {
                                myLogFunc('关闭')
                                click(p.x + 5, p.y + 5);
                                enterNum -= 1;
                                sleep(yanchi1)
                            } else {
                                enterNum = -1;
                            }
                        }
                    }
                } else {
                    let thisImgs = images.read("./res/黑底关闭.png");
                    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
                    let p = findImage(captureScreen(), thisImgs, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), (deviceHeight / 2)], threshold: 0.86 });
                    thisImgs.recycle();
                    if (p) {
                        myLogFunc('关闭')
                        click(p.x + 5, p.y + 5);
                        sleep(yanchi1)
                    }
                }
            } else {
                myLogFunc("升级主城兵营异常")
            }
        }
        if (Boolean(storage.get("sjYanjiu", false)) && cishu < duiwushangxian) {
            let thisImgs2 = images.read("./res/研究所.png");
            thisImgs2 = images.scale(thisImgs2, picJizhun, picJizhunHeight)
            let p2 = findImage(captureScreen(), thisImgs2, { threshold: 0.82 });
            thisImgs2.recycle();
            if (p2) {
                myLogFunc("研究所")
                click(p2.x, p2.y)
                sleep(yanchi2)
                let thisImgs3 = images.read("./res/升级1.png");
                thisImgs3 = images.scale(thisImgs3, picJizhun, picJizhunHeight)
                let p3 = findImage(captureScreen(), thisImgs3, { threshold: 0.86 });
                thisImgs3.recycle();
                if (p3) {
                    click(p3.x, p3.y)
                    sleep(yanchi1)
                    let thisImgs4 = images.read("./res/升级2.png");
                    thisImgs4 = images.scale(thisImgs4, picJizhun, picJizhunHeight)
                    let p4 = findImage(captureScreen(), thisImgs4, { threshold: 0.86 });
                    thisImgs4.recycle();
                    if (p4) {
                        cishu += 1;
                        click(p4.x, p4.y)
                        sleep(yanchi)
                        back()
                        sleep(yanchi1)
                    } else {
                        let enterNum = 2;
                        while (enterNum > 0) {
                            let thisImgs = images.read("./res/黑底关闭.png");
                            thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
                            let p = findImage(captureScreen(), thisImgs, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), (deviceHeight / 2)], threshold: 0.86 });
                            thisImgs.recycle();
                            if (p) {
                                myLogFunc('关闭')
                                click(p.x + 5, p.y + 5);
                                enterNum -= 1;
                                sleep(yanchi1)
                            } else {
                                enterNum = -1;
                            }
                        }
                    }
                } else {
                    let thisImgs = images.read("./res/黑底关闭.png");
                    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
                    let p = findImage(captureScreen(), thisImgs, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), (deviceHeight / 2)], threshold: 0.86 });
                    thisImgs.recycle();
                    if (p) {
                        myLogFunc('关闭')
                        click(p.x + 5, p.y + 5);
                        sleep(yanchi1)
                    }
                }
            } else {
                myLogFunc("升级主城研究所异常")
            }

        }
        if (Boolean(storage.get("sjChengfang", false)) && cishu < duiwushangxian) {
            let thisImgs2 = images.read("./res/城防.png");
            thisImgs2 = images.scale(thisImgs2, picJizhun, picJizhunHeight)
            let p2 = findImage(captureScreen(), thisImgs2, { threshold: 0.82 });
            thisImgs2.recycle();
            if (p2) {
                myLogFunc("升级城防")
                click(p2.x, p2.y)
                sleep(yanchi2)
                let thisImgs3 = images.read("./res/升级1.png");
                thisImgs3 = images.scale(thisImgs3, picJizhun, picJizhunHeight)
                let p3 = findImage(captureScreen(), thisImgs3, { threshold: 0.86 });
                thisImgs3.recycle();
                if (p3) {
                    click(p3.x, p3.y)
                    sleep(yanchi1)
                    let thisImgs4 = images.read("./res/升级2.png");
                    thisImgs4 = images.scale(thisImgs4, picJizhun, picJizhunHeight)
                    let p4 = findImage(captureScreen(), thisImgs4, { threshold: 0.86 });
                    thisImgs4.recycle();
                    if (p4) {
                        cishu += 1;
                        click(p4.x, p4.y)
                        sleep(yanchi)
                        back()
                        sleep(yanchi1)
                    } else {
                        let enterNum = 2;
                        while (enterNum > 0) {
                            let thisImgs = images.read("./res/黑底关闭.png");
                            thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
                            let p = findImage(captureScreen(), thisImgs, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), (deviceHeight / 2)], threshold: 0.86 });
                            thisImgs.recycle();
                            if (p) {
                                myLogFunc('关闭')
                                click(p.x + 5, p.y + 5);
                                enterNum -= 1;
                                sleep(yanchi1)
                            } else {
                                enterNum = -1;
                            }
                        }
                    }
                } else {
                    let thisImgs = images.read("./res/黑底关闭.png");
                    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
                    let p = findImage(captureScreen(), thisImgs, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), (deviceHeight / 2)], threshold: 0.86 });
                    thisImgs.recycle();
                    if (p) {
                        myLogFunc('关闭')
                        click(p.x + 5, p.y + 5);
                        sleep(yanchi1)
                    }
                }
            } else {
                myLogFunc("升级主城城防异常")
            }
        }
        if (Boolean(storage.get("sjSchang", false)) && cishu < duiwushangxian) {
            let thisImgs2 = images.read("./res/市场.png");
            thisImgs2 = images.scale(thisImgs2, picJizhun, picJizhunHeight)
            let p2 = findImage(captureScreen(), thisImgs2, { threshold: 0.82 });
            thisImgs2.recycle();
            if (p2) {
                myLogFunc("升级市场")
                click(p2.x, p2.y)
                sleep(yanchi2)
                let thisImgs3 = images.read("./res/升级1.png");
                thisImgs3 = images.scale(thisImgs3, picJizhun, picJizhunHeight)
                let p3 = findImage(captureScreen(), thisImgs3, { threshold: 0.86 });
                thisImgs3.recycle();
                if (p3) {
                    click(p3.x, p3.y)
                    sleep(yanchi1)
                    let thisImgs4 = images.read("./res/升级2.png");
                    thisImgs4 = images.scale(thisImgs4, picJizhun, picJizhunHeight)
                    let p4 = findImage(captureScreen(), thisImgs4, { threshold: 0.86 });
                    thisImgs4.recycle();
                    if (p4) {
                        cishu += 1;
                        click(p4.x, p4.y)
                        sleep(yanchi)
                        back()
                        sleep(yanchi1)
                    } else {
                        let enterNum = 2;
                        while (enterNum > 0) {
                            let thisImgs = images.read("./res/黑底关闭.png");
                            thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
                            let p = findImage(captureScreen(), thisImgs, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), (deviceHeight / 2)], threshold: 0.86 });
                            thisImgs.recycle();
                            if (p) {
                                myLogFunc('关闭')
                                click(p.x + 5, p.y + 5);
                                enterNum -= 1;
                                sleep(yanchi1)
                            } else {
                                enterNum = -1;
                            }
                        }
                    }
                } else {
                    let thisImgs = images.read("./res/黑底关闭.png");
                    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
                    let p = findImage(captureScreen(), thisImgs, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), (deviceHeight / 2)], threshold: 0.86 });
                    thisImgs.recycle();
                    if (p) {
                        myLogFunc('关闭')
                        click(p.x + 5, p.y + 5);
                        sleep(yanchi1)
                    }
                }
            } else {
                myLogFunc("升级主城市场异常")
            }
        }
        if (Boolean(storage.get("sjJunbei", false)) && cishu < duiwushangxian) {
            let thisImgs2 = images.read("./res/军备.png");
            thisImgs2 = images.scale(thisImgs2, picJizhun, picJizhunHeight)
            let p2 = findImage(captureScreen(), thisImgs2, { threshold: 0.82 });
            thisImgs2.recycle();
            if (p2) {
                myLogFunc("升级军备")
                click(p2.x, p2.y)
                sleep(yanchi2)
                let thisImgs3 = images.read("./res/升级1.png");
                thisImgs3 = images.scale(thisImgs3, picJizhun, picJizhunHeight)
                let p3 = findImage(captureScreen(), thisImgs3, { threshold: 0.86 });
                thisImgs3.recycle();
                if (p3) {
                    click(p3.x, p3.y)
                    sleep(yanchi1)
                    let thisImgs4 = images.read("./res/升级2.png");
                    thisImgs4 = images.scale(thisImgs4, picJizhun, picJizhunHeight)
                    let p4 = findImage(captureScreen(), thisImgs4, { threshold: 0.86 });
                    thisImgs4.recycle();
                    if (p4) {
                        cishu += 1;
                        click(p4.x, p4.y)
                        sleep(yanchi)
                        back()
                        sleep(yanchi1)
                    } else {
                        let enterNum = 2;
                        while (enterNum > 0) {
                            let thisImgs = images.read("./res/黑底关闭.png");
                            thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
                            let p = findImage(captureScreen(), thisImgs, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), (deviceHeight / 2)], threshold: 0.86 });
                            thisImgs.recycle();
                            if (p) {
                                myLogFunc('关闭')
                                click(p.x + 5, p.y + 5);
                                enterNum -= 1;
                                sleep(yanchi1)
                            } else {
                                enterNum = -1;
                            }
                        }
                    }
                } else {
                    let thisImgs = images.read("./res/黑底关闭.png");
                    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
                    let p = findImage(captureScreen(), thisImgs, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), (deviceHeight / 2)], threshold: 0.86 });
                    thisImgs.recycle();
                    if (p) {
                        myLogFunc('关闭')
                        click(p.x + 5, p.y + 5);
                        sleep(yanchi1)
                    }
                }
            } else {
                myLogFunc("升级主城军备异常")
            }
        }

        let enter = true;
        while (enter) {
            let thisImgs = images.read("./res/黑底关闭.png");
            thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
            let p = findImage(captureScreen(), thisImgs, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), (deviceHeight / 2)], threshold: 0.86 });
            thisImgs.recycle();
            if (p) {
                myLogFunc('关闭')
                click(p.x + 5, p.y + 5);
                sleep(yanchi1)
            } else {
                enter = false;
                sleep(yanchi)
            }
        }
    } else {
        log('没有我的主城')
    }
}

// 联盟捐赠
function lianmengjuanzengFunc() {
    sleep(yanchi1)
    // 联盟采集流程
    while (!seeLianmengFunc()) {
        yichangFanhuiFunc("联盟捐赠")
        sleep(yanchi3)
    }
    sleep(yanchi1)
    let thisImgs = images.read("./res/联盟商店.png");
    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
    let p = findImage(captureScreen(), thisImgs, { region: [0, (deviceHeight / 2), (deviceWidth / 2), (deviceHeight / 2)], threshold: 0.8 });
    thisImgs.recycle();
    if (p) {
        myLogFunc('点击联盟商店')
        sleep(yanchi)
        click(p.x, p.y)
        sleep(yanchi1)
        let enter = true;
        while (enter) {
            let thisImgs1 = images.read("./res/贡献.png");
            thisImgs1 = images.scale(thisImgs1, picJizhun, picJizhunHeight)
            let result = findImage(captureScreen(), thisImgs1, { region: [0, 0, (deviceWidth / 2), (deviceHeight - (220 * picJizhun))], threshold: 0.85 });
            thisImgs1.recycle();
            if (result) {
                sleep(yanchi)
                click(result.x, result.y)
            } else {
                enter = false
            }
        }
        sleep(yanchi)
        back()
    } else {
        myLogFunc('error联盟商店')

        yichangFanhuiFunc("联盟商店异常")
        sleep(yanchi1)
        seeLianmengFunc()
        sleep(yanchi2)
        lianmengjianzhuFunc()
    }
}

// 联盟互助
function lianmenghuzhuFunc() {
    sleep(yanchi1)
    // 联盟采集流程
    while (!seeLianmengFunc()) {
        yichangFanhuiFunc("联盟互助")
        sleep(yanchi3)
    }
    sleep(yanchi1)
    let thisImgs = images.read("./res/联盟互助.png");
    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
    let p = findImage(captureScreen(), thisImgs, { region: [0, (deviceHeight / 2), (deviceWidth / 2), (deviceHeight / 2)], threshold: 0.8 });
    thisImgs.recycle();
    if (p) {
        myLogFunc('点击联盟互助')
        sleep(yanchi)
        click(p.x, p.y)
        sleep(yanchi1)

        let thisImgs1 = images.read("./res/全部帮助.png");
        thisImgs1 = images.scale(thisImgs1, picJizhun, picJizhunHeight)
        let result = findImage(captureScreen(), thisImgs1, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)], threshold: 0.85 });
        thisImgs1.recycle();
        if (result) {
            sleep(yanchi)
            click(result.x, result.y)
        }
        sleep(yanchi)
        back()
    } else {
        myLogFunc('error联盟互助')

        yichangFanhuiFunc("联盟互助异常")
        sleep(yanchi1)
        seeLianmengFunc()
        sleep(yanchi2)
        lianmengjianzhuFunc()
    }
}

// 训练士兵
function xunlianshibingFunc() {
    let thisImgs1 = images.read("./res/我的主城.png");
    thisImgs1 = images.scale(thisImgs1, picJizhun, picJizhunHeight)
    let p1 = findImage(captureScreen(), thisImgs1, { region: [(deviceWidth / 4), 150, (deviceWidth / 2), (deviceHeight - 200)], threshold: 0.8 });
    thisImgs1.recycle();
    if (p1) {
        myLogFunc("我的主城")
        click(p1.x, p1.y - 80)
        sleep(yanchi2)
        let thisImgs2 = images.read("./res/兵营.png");
        thisImgs2 = images.scale(thisImgs2, picJizhun, picJizhunHeight)
        let p2 = findImage(captureScreen(), thisImgs2, { threshold: 0.82 });
        thisImgs2.recycle();
        if (p2) {
            myLogFunc("兵营")
            let shangcilianbing = new Date().getTime();
            storage.put("shangcilianbing", shangcilianbing)
            click(p2.x, p2.y)
            sleep(yanchi2)

            if (Boolean(storage.get("gongbing", false))) {
                let thisImgs3 = images.read("./res/君.png");
                thisImgs3 = images.scale(thisImgs3, picJizhun, picJizhunHeight)
                let p3 = findImage(captureScreen(), thisImgs3, { threshold: 0.7 });
                thisImgs3.recycle();
                if (p3) {
                    click(p3.x, p3.y)
                    sleep(yanchi1)
                    let thisImgs4 = images.read("./res/训练.png");
                    thisImgs4 = images.scale(thisImgs4, picJizhun, picJizhunHeight)
                    let p4 = findImage(captureScreen(), thisImgs4, { threshold: 0.86 });
                    thisImgs4.recycle();
                    if (p4) {
                        myLogFunc("训练弓兵")
                        for (let index = 0; index < 8; index++) {
                            click(p4.x, p4.y)
                            sleep(yanchi)
                        }
                        back()
                        sleep(yanchi1)
                    } else {
                        myLogFunc("不可训练")
                    }
                }
            }
            if (Boolean(storage.get("qibing", false))) {
                let thisImgs3 = images.read("./res/臣.png");
                thisImgs3 = images.scale(thisImgs3, picJizhun, picJizhunHeight)
                let p3 = findImage(captureScreen(), thisImgs3, { threshold: 0.7 });
                thisImgs3.recycle();
                if (p3) {
                    click(p3.x, p3.y)
                    sleep(yanchi1)
                    let thisImgs4 = images.read("./res/训练.png");
                    thisImgs4 = images.scale(thisImgs4, picJizhun, picJizhunHeight)
                    let p4 = findImage(captureScreen(), thisImgs4, { threshold: 0.86 });
                    thisImgs4.recycle();
                    if (p4) {
                        myLogFunc("训练骑兵")
                        for (let index = 0; index < 8; index++) {
                            click(p4.x, p4.y)
                            sleep(yanchi)
                        }
                        back()
                        sleep(yanchi1)
                    } else {
                        myLogFunc("不可训练")
                    }
                }
            }
            if (Boolean(storage.get("bubing", false))) {
                let thisImgs3 = images.read("./res/民.png");
                thisImgs3 = images.scale(thisImgs3, picJizhun, picJizhunHeight)
                let p3 = findImage(captureScreen(), thisImgs3, { threshold: 0.7 });
                thisImgs3.recycle();
                if (p3) {
                    click(p3.x, p3.y)
                    sleep(yanchi1)
                    let thisImgs4 = images.read("./res/训练.png");
                    thisImgs4 = images.scale(thisImgs4, picJizhun, picJizhunHeight)
                    let p4 = findImage(captureScreen(), thisImgs4, { threshold: 0.86 });
                    thisImgs4.recycle();
                    if (p4) {
                        myLogFunc("训练步兵")
                        for (let index = 0; index < 8; index++) {
                            click(p4.x, p4.y)
                            sleep(yanchi)
                        }
                        back()
                        sleep(yanchi1)
                    } else {
                        myLogFunc("不可训练")
                    }
                }
            }
            if (Boolean(storage.get("chihou", false))) {
                let thisImgs3 = images.read("./res/侦查.png");
                thisImgs3 = images.scale(thisImgs3, picJizhun, picJizhunHeight)
                let p3 = findImage(captureScreen(), thisImgs3, { threshold: 0.6 });
                thisImgs3.recycle();
                if (p3) {
                    click(p3.x, p3.y)
                    sleep(yanchi1)
                    let thisImgs4 = images.read("./res/训练.png");
                    thisImgs4 = images.scale(thisImgs4, picJizhun, picJizhunHeight)
                    let p4 = findImage(captureScreen(), thisImgs4, { threshold: 0.86 });
                    thisImgs4.recycle();
                    if (p4) {
                        myLogFunc("训练斥候")
                        for (let index = 0; index < 8; index++) {
                            click(p4.x, p4.y)
                            sleep(yanchi)
                        }
                        back()
                        sleep(yanchi1)
                    } else {
                        myLogFunc("不可训练")
                    }
                }
            } else {
                log('没有侦查')
            }
        } else {
            myLogFunc("点击主城练兵异常")
        }

        let enter = true;
        while (enter) {
            let thisImgs = images.read("./res/黑底关闭.png");
            thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
            let p = findImage(captureScreen(), thisImgs, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), (deviceHeight / 2)], threshold: 0.86 });
            thisImgs.recycle();
            if (p) {
                myLogFunc('关闭')
                click(p.x + 5, p.y + 5);
                sleep(yanchi1)
            } else {
                enter = false;
                sleep(yanchi)
            }
        }
    }
}

// 每日任务
// 免费招募
function mianfeizhaomuFunc() {
    let thisImgs1 = images.read("./res/我的主城.png");
    thisImgs1 = images.scale(thisImgs1, picJizhun, picJizhunHeight)
    let p1 = findImage(captureScreen(), thisImgs1, { region: [(deviceWidth / 4), 150, (deviceWidth / 2), (deviceHeight - 200)], threshold: 0.8 });
    thisImgs1.recycle();
    if (p1) {
        myLogFunc("我的主城")
        click(p1.x, p1.y - 80)
        sleep(yanchi2)
        let thisImgs2 = images.read("./res/英雄府.png");
        thisImgs2 = images.scale(thisImgs2, picJizhun, picJizhunHeight)
        let p2 = findImage(captureScreen(), thisImgs2, { threshold: 0.82 });
        thisImgs2.recycle();
        if (p2) {
            myLogFunc("英雄府")
            click(p2.x, p2.y)
            sleep(yanchi2)

            let thisImgs3 = images.read("./res/酒馆.png");
            thisImgs3 = images.scale(thisImgs3, picJizhun, picJizhunHeight)
            let p3 = findImage(captureScreen(), thisImgs3, { threshold: 0.86 });
            thisImgs3.recycle();
            if (p3) {
                myLogFunc("酒馆")
                let thisDateStr = allDateStr + new Date().toDateString();
                storage.put("allDateStr", thisDateStr)
                allDateStr = storage.get("allDateStr", "")
                click(p3.x, p3.y)
                sleep(yanchi2)
                let thisImgs4 = images.read("./res/免费刷新.png");
                thisImgs4 = images.scale(thisImgs4, picJizhun, picJizhunHeight)
                let p4 = findImage(captureScreen(), thisImgs4, { threshold: 0.85 });
                thisImgs4.recycle();
                if (p4) {
                    myLogFunc("免费刷新")
                    click(p4.x, p4.y)
                    sleep(yanchi2)
                    let thisImgs5 = images.read("./res/免费加入.png");
                    thisImgs5 = images.scale(thisImgs5, picJizhun, picJizhunHeight)
                    let p5 = findImage(captureScreen(), thisImgs5, { threshold: 0.8 });
                    thisImgs5.recycle();
                    if (p5) {
                        myLogFunc("免费加入")
                        click(p5.x, p5.y)
                        sleep(yanchi1)
                    }
                } else {
                    let thisImgs5 = images.read("./res/免费加入.png");
                    thisImgs5 = images.scale(thisImgs5, picJizhun, picJizhunHeight)
                    let p5 = findImage(captureScreen(), thisImgs5, { threshold: 0.85 });
                    thisImgs5.recycle();
                    if (p5) {
                        myLogFunc("免费加入")
                        click(p5.x, p5.y)
                        sleep(yanchi1)
                    } else {
                        myLogFunc("已免费招募")
                    }
                }
            }
        } else {
            myLogFunc("点击主城酒馆异常")
        }

        let enter = true;
        while (enter) {
            let thisImgs = images.read("./res/黑底关闭.png");
            thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
            let p = findImage(captureScreen(), thisImgs, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), (deviceHeight / 2)], threshold: 0.86 });
            thisImgs.recycle();
            if (p) {
                myLogFunc('关闭')
                click(p.x + 5, p.y + 5);
                sleep(yanchi1)
            } else {
                enter = false;
                sleep(yanchi)
            }
        }
    }
}

// 采集任务集合
// 采集队列读取
function caijiduilieFunc(bloo) {
    if (yuanbaoweizhi.y == 0) {
        myLogFunc('第一次滑动参数')
        sleep(yanchi1)
        let thisImgs = images.read("./res/元宝.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let p = findImage(captureScreen(), thisImgs, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), (deviceHeight / 2)], threshold: 0.86 });
        thisImgs.recycle();
        if (p) {
            log('滑动参数元宝位置')
            let newObj = { x: p.x, y: p.y };
            storage.put("yuanbaoweizhi", newObj);
            yuanbaoweizhi = storage.get("yuanbaoweizhi", { x: 2020, y: 0 });
            swipe(yuanbaoweizhi.x, youshangDuilie.y, (yuanbaoweizhi.x + (200 * picJizhun)), youshangDuilie.y, 500)
            sleep(yanchi)
        }
    } else {
        log('滑动参数位置')
        swipe(yuanbaoweizhi.x, youshangDuilie.y, (yuanbaoweizhi.x - (200 * picJizhun)), youshangDuilie.y, 500)
        sleep(yanchi)
    }
    log('队列区域', youshangDuilie)
    let captureScreenTT = captureScreen();
    let thisImgs = images.read("./res/caiji.png");
    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
    let myThre = 0.7;
    if (deviceHeight == 1080) {
        myThre = 0.75;
    } else {
        myThre = 0.71;
    }
    let result = images.matchTemplate(captureScreenTT, thisImgs, { region: [youshangDuilie.x, youshangDuilie.y, youshangDuilie.w, youshangDuilie.h], threshold: myThre, max: 4 });
    thisImgs.recycle();
    myLogFunc('读取队列')
    log("result", result)
    if (bloo) {
        caijiduiwu = duiwushangxian;
    } else {
        if (result && result.matches.length) {
            caijiduiwu = result.matches.length;
            if (caijiduiwu <= 1) {
                myLogFunc('可派出采集')
                zuiduancaiji = 0;
            } else {
                myLogFunc('采集队列' + caijiduiwu)
                if (caijiduiwu >= duiwushangxian) {
                    zuiduancaiji = zuiduancaijiFunc()
                }
            }
        } else {
            caijiduiwu = 0
            myLogFunc('未派出采集')
        }
    }
    if (Boolean(storage.get("openDixi", false)) && dixiTishi) {
        let thisImgsNs = images.read("./res/dixitishi.png");
        thisImgsNs = images.scale(thisImgsNs, picJizhun, picJizhunHeight)
        let pNs = images.matchTemplate(captureScreenTT, thisImgsNs, { region: [youshangDuilie.x, youshangDuilie.y, youshangDuilie.w, youshangDuilie.h], threshold: 0.82 });
        thisImgsNs.recycle();
        if (pNs.matches.length) {
            dixiTishiFunc(pNs.matches)
        }
    }
}

// 敌袭检测
function dixiJianceFunc() {
    if (Boolean(storage.get("openDixi", false)) && dixiTishi) {
        let jieguo = "";
        if (yuanbaoweizhi.y == 0) {
            myLogFunc('第一次敌袭参数')
            sleep(yanchi1)
            let thisImgs = images.read("./res/元宝.png");
            thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
            let p = findImage(captureScreen(), thisImgs, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), (deviceHeight / 2)], threshold: 0.86 });
            thisImgs.recycle();
            if (p) {
                log('敌袭检测元宝位置')
                let newObj = { x: p.x, y: p.y };
                storage.put("yuanbaoweizhi", newObj);
                yuanbaoweizhi = storage.get("yuanbaoweizhi", { x: 2020, y: 0 });
                swipe(yuanbaoweizhi.x, youshangDuilie.y, (yuanbaoweizhi.x + (200 * picJizhun)), youshangDuilie.y, 500)
                sleep(yanchi)
            }
        } else {
            log('敌袭检测位置')
            swipe(yuanbaoweizhi.x, youshangDuilie.y, (yuanbaoweizhi.x + (200 * picJizhun)), youshangDuilie.y, 500)
            sleep(yanchi)
        }

        // let clip = images.clip(captureScreen(), youshangDuilie.x, youshangDuilie.y, youshangDuilie.w, youshangDuilie.h);
        // log('读取敌袭') // #522021
        // let result1 = "";
        // if (shibiefangshi == 0) {
        //     result1 = gmlkit.ocr(clip, "zh");
        //     jieguo = result1.text;
        // } else if (shibiefangshi == 1) {
        //     result1 = paddle.ocrText(clip);
        //     jieguo = JSON.stringify(result1);
        // } else {
        //     result1 = gmlkit.ocr(clip, "zh");
        //     jieguo = result1.text;
        // }
        // clip.recycle();
        // log(jieguo)

        // let dixiNum = jieguo.match(/敌装|故|丹/g)

        let thisImgsNs = images.read("./res/dixitishi.png");
        thisImgsNs = images.scale(thisImgsNs, picJizhun, picJizhunHeight)
        let pNs = images.matchTemplate(captureScreen(), thisImgsNs, { region: [youshangDuilie.x, youshangDuilie.y, youshangDuilie.w, youshangDuilie.h], threshold: 0.85 });
        thisImgsNs.recycle();
        if (pNs.matches.length) {
            // if (dixiNum) {}
            myLogFunc('敌袭 敌袭')
            log("敌袭", jieguo)
            if (Boolean(storage.get("dixiyoujian", false))) {
                myLogFunc('敌袭 邮件提醒')
                let userrEmail = storage.get("userrEmail", "")
                if (isEmailValid(userrEmail)) {
                    dixiTishi = false
                    dixitzFunc()
                } else {
                    myLogFunc('邮件地址错误')
                }
            }
            if (Boolean(storage.get("fanjiduiwu", false))) {
                fanjiduiwuFunc(pNs.matches)
            }
            if (Boolean(storage.get("dixichecaiji", false))) {
                dixichecaijiFunc()
            }
            if (Boolean(storage.get("dixiyuyin", false))) {
                myLogFunc('敌袭 语音')
                let path = files.path("./res/dixiyuyin.MP3")
                media.playMusic(path);
                sleep(media.getMusicDuration());
                media.playMusic("./res/dixiyuyin.MP3");
            }
            if (Boolean(storage.get("dixizhendong", false))) {
                myLogFunc('敌袭 震动')
                device.vibrate(10000)
                for (let index = 0; index < 6; index++) {
                    device.vibrate(5000)
                    sleep(2000)
                }
            }
        }
    }
}

// 敌袭提示
function dixiTishiFunc(matches) {
    myLogFunc('敌袭 敌袭')
    log("敌袭", matches)
    if (Boolean(storage.get("dixiyoujian", false))) {
        myLogFunc('敌袭 邮件提醒')
        let userrEmail = storage.get("userrEmail", "")
        if (isEmailValid(userrEmail)) {
            dixiTishi = false
            dixitzFunc()
        } else {
            myLogFunc('邮件地址错误')
        }
    }
    if (Boolean(storage.get("fanjiduiwu", false))) {
        fanjiduiwuFunc(matches)
    }
    if (Boolean(storage.get("dixichecaiji", false))) {
        dixichecaijiFunc()
    }
    if (Boolean(storage.get("dixiyuyin", false))) {
        myLogFunc('敌袭 语音')
        let path = files.path("./res/dixiyuyin.MP3")
        media.playMusic(path);
        sleep(media.getMusicDuration());
        media.playMusic("./res/dixiyuyin.MP3");
    }
    if (Boolean(storage.get("dixizhendong", false))) {
        myLogFunc('敌袭 震动')
        device.vibrate(10000)
        for (let index = 0; index < 6; index++) {
            device.vibrate(5000)
            sleep(2000)
        }
    }
}

// 敌袭邮件提示
function dixitzFunc() {
    // 请求服务
    let req = http.postJson("http://123.60.43.199:8866/main/v1/auto/EmailNotifier", {
        activationCode: storage.get("jihuoma", ""),
        aap: "yxsXysj",
        deviceWidth: device.width,
        deviceHeight: device.height,
        brand: device.brand,
        versionCode: project.versionCode,
        release: device.release,
        sdkInt: device.sdkInt,
        androidId: device.getAndroidId(),
        fingerprint: device.fingerprint,
        startTime: new Date().getTime(),
        email: storage.get("userrEmail", "")
    });
    let rJson = req.body.json();
    if (rJson.code != 200) {
        let message = rJson.message ? rJson.message : "服务异常请联系客服！";
        toastLog(message)
        myLogFunc(message)
        sleep(yanchi1)
    } else {
        myLogFunc("已发送邮件通知！")
    }
}

// 领取军报
function lqjunbaoFunc() {
    sleep(yanchi1)
    myLogFunc("领取军报")
    let thisImgs = images.read("./res/军报.png");
    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
    let p = findImage(captureScreen(), thisImgs, { region: [0, 0, (deviceWidth / 2), (deviceHeight / 2)], threshold: 0.8 });
    thisImgs.recycle();
    if (p) {
        click(p.x, p.y);
        sleep(yanchi2)

        let thisImgs1 = images.read("./res/一键领取.png");
        thisImgs1 = images.scale(thisImgs1, picJizhun, picJizhunHeight)
        let p1 = findImage(captureScreen(), thisImgs1, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)], threshold: 0.8 });
        thisImgs1.recycle();
        if (p1) {
            click(p1.x + 50, p1.y + 20);
            sleep(yanchi2)
            myLogFunc("一键领取")
            click(p1.x + 50, p1.y + 20);
            sleep(yanchi2)
            let thisImgs2 = images.read("./res/蓝底关闭.png");
            thisImgs2 = images.scale(thisImgs2, picJizhun, picJizhunHeight)
            let p2 = findImage(captureScreen(), thisImgs2, { region: [0, 0, deviceWidth, (deviceHeight / 2)], threshold: 0.8 });
            if (p2) {
                click(p2.x, p2.y);
                sleep(yanchi1)
            } else {
                back()
                sleep(yanchi1)
                let thisImgs3 = images.read("./res/蓝底关闭.png");
                thisImgs3 = images.scale(thisImgs3, picJizhun, picJizhunHeight)
                let p3 = findImage(captureScreen(), thisImgs3, { region: [0, 0, deviceWidth, (deviceHeight / 2)], threshold: 0.8 });
                if (p3) {
                    click(p3.x, p3.y);
                    sleep(yanchi1)
                }
            }
        } else {
            myLogFunc("暂无军报")
            back()
            sleep(yanchi2)
        }
    }
}

// 自动征收
function zhengshouFunc() {
    sleep(yanchi1)
    myLogFunc("自动征收")
    let thisImgs = images.read("./res/天选.png");
    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
    let p = findImage(captureScreen(), thisImgs, { region: [0, 0, (deviceWidth / 2), (deviceHeight / 2)], threshold: 0.8 });
    thisImgs.recycle();
    if (p) {
        click(p.x, p.y);
        sleep(yanchi2)

        let thisImgs1 = images.read("./res/一键征收.png");
        thisImgs1 = images.scale(thisImgs1, picJizhun, picJizhunHeight)
        let p1 = findImage(captureScreen(), thisImgs1, { region: [0, 0, deviceWidth, deviceHeight], threshold: 0.8 });
        thisImgs1.recycle();
        if (p1) {
            myLogFunc("一键征收")
            click(p1.x + 50, p1.y + 20);
            sleep(yanchi3)
            let thisImgs2 = images.read("./res/强征一次.png");
            thisImgs2 = images.scale(thisImgs2, picJizhun, picJizhunHeight)
            let p2 = findImage(captureScreen(), thisImgs2, { region: [0, 0, deviceWidth, deviceHeight], threshold: 0.8 });
            thisImgs2.recycle();
            if (p2) {
                myLogFunc("目前不可征收")
                let thisImgs3 = images.read("./res/蓝底关闭.png");
                thisImgs3 = images.scale(thisImgs3, picJizhun, picJizhunHeight)
                let p3 = findImage(captureScreen(), thisImgs3, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), deviceHeight], threshold: 0.8 });
                thisImgs3.recycle();
                if (p3) {
                    click(p3.x, p3.y);
                    p3 = null
                    sleep(yanchi1)
                }

                sleep(yanchi1)
                let thisImgs4 = images.read("./res/天选关闭.png");
                thisImgs4 = images.scale(thisImgs4, picJizhun, picJizhunHeight)
                let p4 = findImage(captureScreen(), thisImgs4, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), deviceHeight], threshold: 0.8 });
                thisImgs4.recycle();
                if (p4) {
                    click(p4.x, p4.y);
                    p4 = null
                    sleep(yanchi1)
                }
            } else {
                log("没有强征，确定征收")
                sleep(yanchi3)
                sleep(yanchi1)
                // 征收啊
                let thisImgs5 = images.read("./res/确认.png");
                thisImgs5 = images.scale(thisImgs5, picJizhun, picJizhunHeight)
                let p5 = findImage(captureScreen(), thisImgs5, { region: [0, 0, deviceWidth, deviceHeight], threshold: 0.8 });
                thisImgs5.recycle();
                if (p5) {
                    click(p5.x, p5.y);
                    p5 = null
                    sleep(yanchi1)
                }

                sleep(yanchi1)
                let thisImgs4 = images.read("./res/天选关闭.png");
                thisImgs4 = images.scale(thisImgs4, picJizhun, picJizhunHeight)
                let p4 = findImage(captureScreen(), thisImgs4, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), deviceHeight], threshold: 0.8 });
                thisImgs4.recycle();
                if (p4) {
                    click(p4.x, p4.y);
                    p4 = null
                    sleep(yanchi1)
                }

            }
        } else {
            myLogFunc("自动征收页面异常")
            back()
            fanhuizhuchengFunc()
            sleep(yanchi2)
        }
    }
}


// 领取任务
function lingqurenwuFunc() {
    myLogFunc("领取任务")
    sleep(yanchi1)
    let thisImgs = images.read("./res/任务.png");
    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
    let p = findImage(captureScreen(), thisImgs, { region: [0, 0, (deviceWidth / 2), (deviceHeight / 2)], threshold: 0.8 });
    thisImgs.recycle();
    if (p) {
        click(p.x, p.y);
        sleep(yanchi1)
        sleep(yanchi)
        let thisImgsN = images.read("./res/限时兑换.png");
        thisImgsN = images.scale(thisImgsN, picJizhun, picJizhunHeight)
        let pN = findImage(captureScreen(), thisImgsN, { threshold: 0.72 });
        thisImgsN.recycle();
        if (pN) {
            myLogFunc('限时任务')
            lmNontinue = 16;
        } else {
            myLogFunc('没有限时任务活动')
            lmNontinue = 0;
        }
        let thisImgs1 = images.read("./res/领取按钮.png");
        thisImgs1 = images.scale(thisImgs1, picJizhun, picJizhunHeight);
        let thisImgs5 = images.read("./res/确认.png");
        thisImgs5 = images.scale(thisImgs5, picJizhun, picJizhunHeight)
        let whileLoop = true;
        while (whileLoop) {
            log('活跃任务轮询')
            sleep(yanchi1)
            whileLoop = true
            let p1 = findImage(captureScreen(), thisImgs1, { region: [0, 0, deviceWidth, deviceHeight], threshold: 0.8 });
            if (p1) {
                myLogFunc("点击领取")
                click(p1.x + 50, p1.y + 20);
                sleep(yanchi3)
                let p5 = findImage(captureScreen(), thisImgs5, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)], threshold: 0.8 });
                if (p5) {
                    log('确认领取！')
                    click(p5.x, p5.y);
                    p5 = null
                    sleep(yanchi2)
                }
            } else {
                log('没有活跃任务了')
                sleep(yanchi)
                whileLoop = false
                let thisImgs6 = images.read("./res/关闭任务.png");
                thisImgs6 = images.scale(thisImgs6, picJizhun, picJizhunHeight)
                let p6 = findImage(captureScreen(), thisImgs6);
                thisImgs6.recycle();
                if (p6) {
                    myLogFunc('关闭活跃任务')
                    click(p6.x, p6.y);
                    p6 = null
                    sleep(yanchi1)
                }
            }
        }
        thisImgs5.recycle();
        thisImgs1.recycle();
    }
}

// 查看限时任务
function seeTimerenwuFunc() {
    myLogFunc("查看限时任务")
    sleep(yanchi1)
    let thisImgs = images.read("./res/任务.png");
    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
    let p = findImage(captureScreen(), thisImgs, { region: [0, 0, (deviceWidth / 2), (deviceHeight / 2)], threshold: 0.8 });
    thisImgs.recycle();
    if (p) {
        click(p.x, p.y);
        sleep(yanchi1)
        let thisImgsN = images.read("./res/限时兑换.png");
        thisImgsN = images.scale(thisImgsN, picJizhun, picJizhunHeight)
        let pN = findImage(captureScreen(), thisImgsN, { threshold: 0.86 });
        thisImgsN.recycle();
        if (pN) {
            myLogFunc('限时任务')
            lmNontinue = 16;
        } else {
            myLogFunc('没有限时任务活动')
            lmNontinue = 0;
        }
        sleep(yanchi)
        let thisImgs6 = images.read("./res/关闭任务.png");
        thisImgs6 = images.scale(thisImgs6, picJizhun, picJizhunHeight)
        let p6 = findImage(captureScreen(), thisImgs6, { threshold: 0.85 });
        thisImgs6.recycle();
        if (p6) {
            myLogFunc('关闭活跃任务')
            click(p6.x, p6.y);
            p6 = null
            sleep(yanchi1)
        }
    }
}

// 返回自己主城
function fanhuizhuchengFunc() {
    myLogFunc('返回主城')
    // 返回自己主城
    if (shangciweizhi.x == 0) {
        let thisImgs = images.read("./res/上次位置.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let p = findImage(captureScreen(), thisImgs, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)], threshold: 0.8 });
        thisImgs.recycle();
        if (p) {
            let newObj = { x: p.x, y: p.y };
            storage.put("shangciweizhi", newObj);
            shangciweizhi = storage.get("shangciweizhi", { x: 0, y: 0 });
        }
    }
    if (shangciweizhi.x == 0) {
        let thisImgs1 = images.read("./res/小主城.png");
        thisImgs1 = images.scale(thisImgs1, picJizhun, picJizhunHeight)
        let p1 = findImage(captureScreen(), thisImgs1, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)], threshold: 0.85 });
        thisImgs1.recycle();
        if (p1) {
            let newObj = { x: p1.x, y: p1.y };
            storage.put("shangciweizhi", newObj);
            shangciweizhi = storage.get("shangciweizhi", { x: 0, y: 0 });
        }
    }
    let whileLoop = true;
    let rongcuoNum = 0;
    while (whileLoop) {
        let thisImgs1 = images.read("./res/我的主城.png");
        thisImgs1 = images.scale(thisImgs1, picJizhun, picJizhunHeight)
        let p1 = findImage(captureScreen(), thisImgs1, { region: [(deviceWidth / 4), 150, (deviceWidth / 2), (deviceHeight - 200)], threshold: 0.8 });
        thisImgs1.recycle();
        if (p1) {
            whileLoop = false;
        } else {
            if (shangciweizhi.x) {
                sleep(yanchi)
                click(shangciweizhi.x, shangciweizhi.y);
                rongcuoNum = rongcuoNum + 1;
                sleep(yanchi2)
                if (rongcuoNum > secureNum) {
                    myLogFunc('返回主城受阻关闭');
                    xiaojinglingJc()
                    sleep(yanchi)
                    whileLoop = false;
                    fanhuizhuchengFunc()
                }
            } else {
                whileLoop = false;
                fanhuizhuchengFunc()
            }

        }
    }
    myLogFunc('完成返回主城');
}
// 自定义比较函数
function compare(a) {
    if (a.type === caijileixingYx) return -1; // 目标值应该排在前面
    else return a; // 其他值按默认顺序排列
}
// 采集资源
function caijiziyuanFunc() {
    // 进行采集查看
    if (caijiduiwu > 1) {
        caijichakanFunc()
    }
    // 联盟采集
    lianmengcajiFunc()
    if (!Boolean(storage.get("zhicaifujin", false)) && Boolean(storage.get("dongtaizyyouxian", false)) && toCaijiList.length) {
        // 采集资源优先级
        caijiziyuanyxFunc()
    }
    // 采集备战署
    if (Boolean(storage.get("isSanguo", false))) {
        lianmengcajiFunc(2)
    }
    // 资源存仓库
    if (Boolean(storage.get("ziyuancunchu", false))) {
        ziyuancuncangku()
    }
    // 保险再次识别
    myLogFunc('确认队列')
    caijiduilieFunc()

    if (!Boolean(storage.get("zhicaifujin", false))) {
        let thisTimes = new Date().getHours();
        let bcj1 = Number(storage.get("bucaijishiduan1", "1"));
        let bcj2 = Number(storage.get("bucaijishiduan2", "5"));
        if (Boolean(storage.get("bucaijishiduan", false)) && thisTimes > bcj1 && thisTimes < bcj2) {
            let datass = new Date();
            datass.setHours(15)
            datass.setMinutes(1)
            zuiduancaiji = datass.getTime();
            myLogFunc('该时段不采集坐标')
        } else {
            // 定点采集流程
            myLogFunc("坐标采集")
            for (let index = 0; index < toCaijiList.length; index++) {
                if (xiaobingbuzu) {
                    myLogFunc('缺乏兵力资源')
                    break;
                }
                log('采集队列: ', caijiduiwu)
                if (caijiduiwu >= duiwushangxian) {
                    myLogFunc('已经派出全部采集')
                    break;
                }
                sleep(yanchi1)
                // 查看世界地图
                seeShijieditu()
                // 点击小地图 跳转指定位置
                goXyFunc(toCaijiList[index].x, toCaijiList[index].y);
                // 高频检测敌袭
                if (Boolean(storage.get("dixigaopinJc", false)) && dixiTishi) {
                    dixiJianceFunc()
                }
                // 区域没有可采集资源跳过本次循环
                if (!seeZiyuanFunc(true)) {
                    continue;
                }
                sleep(yanchi2)

                if (cajiAnniuFunc()) {
                    sleep(yanchi2)
                    caijiYingxiongFunc()
                    if (!xiaobingbuzu) {
                        caijiChufaFunc()
                        sleep(yanchi2)
                    }
                    sleep(yanchi2)
                }
                sleep(yanchi)
            }
        }
    }


    // 备用采集
    if (!xiaobingbuzu) {
        if (caijiduiwu < duiwushangxian) {
            myLogFunc('采集队伍空缺')
            if (Boolean(storage.get("beixuanziyuan", true))) {
                myLogFunc('采集附近资源')
                fanhuizhuchengFunc();
                // 如果包含自己的资源
                if (Boolean(storage.get("baohanziji", false))) {
                    myLogFunc('先查看自己附近')
                    // 自己附近区域采集 不返回上次位置
                    toAllZiyuanFunc(true)
                }

                if (caijiduiwu < duiwushangxian) {
                    // 执行上下左右 上
                    for (let index = 0; index < Number(storage.get("beixuanziyuanFw", "3")); index++) {
                        swipeRandom(deviceWidth * 0.5, deviceHeight * 0.5, deviceWidth * 0.5, deviceHeight * 0.85, 1000);
                        sleep(yanchi2)
                        // 新视野区域采集
                        toAllZiyuanFunc()
                    }
                    fanhuizhuchengFunc();
                }


                if (caijiduiwu < duiwushangxian) {
                    // 执行上下左右 下
                    for (let index = 0; index < Number(storage.get("beixuanziyuanFw", "3")); index++) {
                        swipeRandom(deviceWidth * 0.5, deviceHeight * 0.5, deviceWidth * 0.5, deviceHeight * 0.15, 1000);
                        sleep(yanchi2)
                        // 新视野区域采集
                        toAllZiyuanFunc()
                    }
                    fanhuizhuchengFunc();
                }


                if (caijiduiwu < duiwushangxian) {
                    // 执行上下左右 左
                    for (let index = 0; index < Number(storage.get("beixuanziyuanFw", "3")); index++) {
                        swipeRandom(deviceWidth * 0.5, deviceHeight * 0.5, (deviceWidth - 300), deviceHeight * 0.5, 2500);
                        sleep(yanchi2)
                        // 新视野区域采集
                        toAllZiyuanFunc()
                    }
                    fanhuizhuchengFunc();
                }

                if (caijiduiwu < duiwushangxian) {
                    // 执行上下左右 右
                    for (let index = 0; index < Number(storage.get("beixuanziyuanFw", "3")); index++) {
                        swipeRandom(deviceWidth * 0.5, deviceHeight * 0.5, (300), deviceHeight * 0.5, 2500);
                        sleep(yanchi2)
                        // 新视野区域采集
                        toAllZiyuanFunc()
                    }
                    fanhuizhuchengFunc();
                }
            }
        }
    } else {
        myLogFunc("小兵不足")
    }
}

// 采集资源优先级
function caijiziyuanyxFunc() {
    myLogFunc("采集资源优先级")
    sleep(yanchi1)
    myLogFunc("前往偏僻区读取资源")
    // 查看世界地图
    seeShijieditu()
    // 点击小地图 跳转指定位置
    if (Boolean(storage.get("isSanguo", false))) {
        goXyFunc(150, 145);
    } else {
        goXyFunc(238, 238);
    }
    sleep(yanchi2)
    let zuixiaozhi = 0;
    let thisImgs1 = images.read("./res/粮238.png");
    thisImgs1 = images.scale(thisImgs1, picJizhun, picJizhunHeight)
    let p1 = findImage(captureScreen(), thisImgs1, { region: [0, 0, deviceWidth, 200], threshold: 0.8 });
    thisImgs1.recycle();
    if (p1) {
        let qidian = p1.x + (60 * picJizhun);
        let clip = images.clip(captureScreen(), qidian, 1, (125 * picJizhun), 80);
        let result1 = "";
        if (shibiefangshi == 0) {
            result1 = gmlkit.ocr(clip, "zh");
            result1 = result1.text;
        } else if (shibiefangshi == 1) {
            result1 = paddle.ocrText(clip);
            result1 = result1[0]
        } else {
            result1 = gmlkit.ocr(clip, "zh");
            result1 = result1.text;
        }
        clip.recycle();
        if (result1.includes("万")) {
            result1 = result1.split("万")
            result1 = result1[0] * 10000;
        }
        if (!zuixiaozhi) {
            zuixiaozhi = Number(result1);
            caijileixingYx = 0;
        } else {
            if (Number(result1) < zuixiaozhi) {
                zuixiaozhi = Number(result1);
                caijileixingYx = 0;
            }
        }
        myLogFunc('粮:' + parseInt(result1))
    }
    sleep(yanchi)
    let thisImgs2 = images.read("./res/木238.png");
    thisImgs2 = images.scale(thisImgs2, picJizhun, picJizhunHeight)
    let p2 = findImage(captureScreen(), thisImgs2, { region: [0, 0, deviceWidth, 200], threshold: 0.8 });
    thisImgs2.recycle();
    if (p2) {
        log('p2', p2)
        let qidian = p2.x + (60 * picJizhun);
        let clip = images.clip(captureScreen(), qidian, 1, (125 * picJizhun), 80);
        let result1 = "";
        if (shibiefangshi == 0) {
            result1 = gmlkit.ocr(clip, "zh");
            result1 = result1.text;
        } else if (shibiefangshi == 1) {
            result1 = paddle.ocrText(clip);
            result1 = result1[0]
        } else {
            result1 = gmlkit.ocr(clip, "zh");
            result1 = result1.text;
        }
        clip.recycle();
        if (result1.includes("万")) {
            result1 = result1.split("万")
            result1 = result1[0] * 10000;
        }
        if (!zuixiaozhi) {
            zuixiaozhi = Number(result1);
            caijileixingYx = 1;
        } else {
            if (Number(result1) < zuixiaozhi) {
                zuixiaozhi = Number(result1);
                caijileixingYx = 1;
            }
        }
        myLogFunc('木:' + parseInt(result1))
    }
    sleep(yanchi)
    let thisImgs3 = images.read("./res/矿238.png");
    thisImgs3 = images.scale(thisImgs3, picJizhun, picJizhunHeight)
    let p3 = findImage(captureScreen(), thisImgs3, { region: [0, 0, deviceWidth, 200], threshold: 0.8 });
    thisImgs3.recycle();
    if (p3) {
        log('p3', p3)
        let qidian = p3.x + (60 * picJizhun);
        let clip = images.clip(captureScreen(), qidian, 1, (125 * picJizhun), 80);
        let result1 = "";
        if (shibiefangshi == 0) {
            result1 = gmlkit.ocr(clip, "zh");
            result1 = result1.text;
        } else if (shibiefangshi == 1) {
            result1 = paddle.ocrText(clip);
            result1 = result1[0]
        } else {
            result1 = gmlkit.ocr(clip, "zh");
            result1 = result1.text;
        }
        clip.recycle();
        if (result1.includes("万")) {
            result1 = result1.split("万")
            result1 = result1[0] * 10000;
        }
        if (!zuixiaozhi) {
            zuixiaozhi = Number(result1);
            caijileixingYx = 2;
        } else {
            if (Number(result1) < zuixiaozhi) {
                zuixiaozhi = Number(result1);
                caijileixingYx = 2;
            }
        }
        myLogFunc('矿:' + parseInt(result1))
    }
    switch (caijileixingYx) {
        case 0:
            myLogFunc("优先采粮")
            break;
        case 1:
            myLogFunc("优先采木")
            break;
        case 2:
            myLogFunc("优先采矿")
            break;
        default:
            break;
    }
    toCaijiList = storage.get("caijiItems", [{ x: 66, y: 66, level: 1, type: 2 }, { x: 88, y: 88, level: 2, type: 1 }]); // 资源列表 坐标 等级 类型 粮木矿-123
    // 调用 sort() 进行排序
    toCaijiList.sort(compare);
    // 高频检测敌袭
    if (Boolean(storage.get("dixigaopinJc", false)) && dixiTishi) {
        dixiJianceFunc()
    }
    // 返回主城
    fanhuizhuchengFunc();
}

// 联盟采集
function lianmengcajiFunc(inx) {
    let ind = 0;
    if (inx) {
        ind = inx
    }
    sleep(yanchi1)
    // 联盟采集流程
    while (!seeLianmengFunc()) {
        yichangFanhuiFunc("联盟采集异常")
        sleep(yanchi3)
    }
    sleep(yanchi1)
    lianmengjianzhuFunc()
    sleep(yanchi1)
    let bool = qianwangziyuanFunc(ind)
    if (!bool) {
        sleep(yanchi2)
        return;
    }
    sleep(yanchi2)
    let nengfouCaiji = cajiAnniuFunc(true, true)
    myLogFunc('能否采集' + nengfouCaiji)
    if (nengfouCaiji) {
        sleep(yanchi2)
        // 默认联盟负重优先
        caijiYingxiongFunc(true)
        sleep(yanchi2)
        if (!xiaobingbuzu) {
            caijiChufaFunc()
            sleep(yanchi2)
        } else {
            myLogFunc('联盟采集小兵不足')
        }
    }
    sleep(yanchi1)
}

// 仓库取资源
function cangkuquziyuan() {
    sleep(yanchi1)
    // 联盟采集流程
    while (!seeLianmengFunc()) {
        yichangFanhuiFunc("仓库取资源异常")
        sleep(yanchi3)
    }
    sleep(yanchi1)
    lianmengjianzhuFunc()
    sleep(yanchi1)
    let bool = qianwangziyuanFunc(1)
    if (!bool) {
        sleep(yanchi2)
        return;
    }
    sleep(yanchi2)
    let a = true;
    while (a) {
        var point = findColor(captureScreen(), "#52BE84", { region: [(deviceWidth / 2), 0, (deviceWidth / 2), deviceHeight] });
        if (point) {
            click(point.x, point.y)
        } else {
            a = false
            log("没有取资源颜色")
        }
    }
    myLogFunc("资源已取出")
    lmzyGuanbiFunc();
    sleep(yanchi1)
}

// 资源存仓库
function ziyuancuncangku() {
    sleep(yanchi1)
    // 联盟采集流程
    while (!seeLianmengFunc()) {
        yichangFanhuiFunc("资源存仓库异常")
        sleep(yanchi3)
    }
    sleep(yanchi1)
    lianmengjianzhuFunc()
    sleep(yanchi1)
    let bool = qianwangziyuanFunc(1)
    if (!bool) {
        sleep(yanchi2)
        return;
    }
    sleep(yanchi2)
    let thisImgs = images.read("./res/存十万.png");
    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
    let result = images.matchTemplate(captureScreen(), thisImgs, { threshold: 0.86, max: 3 });
    thisImgs.recycle();
    let matchRc = result.sortBy("top-bottom").matches;
    if (matchRc.length) {
        myLogFunc("存十万", matchRc.length)
        for (let indes = 0; indes < 4; indes++) {
            for (let index = 0; index < matchRc.length; index++) {
                click(matchRc[index].point.x + 10, matchRc[index].point.y + 2);
                sleep(yanchi)
            }
        }
    }
    sleep(yanchi1)
    let thisImgs1 = images.read("./res/存一万.png");
    thisImgs1 = images.scale(thisImgs1, picJizhun, picJizhunHeight)
    let result1 = images.matchTemplate(captureScreen(), thisImgs1, { threshold: 0.86, max: 3 });
    thisImgs1.recycle();
    let matchRc1 = result1.sortBy("top-bottom").matches;
    if (matchRc1.length) {
        myLogFunc("存一万", matchRc1.length)
        for (let indes = 0; indes < 8; indes++) {
            for (let index = 0; index < matchRc1.length; index++) {
                click(matchRc1[index].point.x + 10, matchRc1[index].point.y + 2);
                sleep(200)
            }
        }
    }
    myLogFunc("资源已存")
    lmzyGuanbiFunc();
    sleep(yanchi1)
}

// 查看采集存量
function caijichakanFunc() {
    if (cunliangWeizhi.x == 0) {
        myLogFunc("无需查看存量")
        return;
    }
    let thisImgs = images.read("./res/caijizhong.png");
    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
    let result = images.matchTemplate(captureScreen(), thisImgs, { region: [youshangDuilie.x, youshangDuilie.y, youshangDuilie.w, youshangDuilie.h], threshold: 0.72, max: 4 });
    thisImgs.recycle();
    if (result && result.matches.length) {
        let matchRc1 = result.sortBy("left-right").matches;
        for (let index = 0; index < matchRc1.length; index++) {
            log('进入采集查看', matchRc1[index])
            click(matchRc1[index].point.x + 15, matchRc1[index].point.y)
            sleep(yanchi2)
            log('采集中资源')
            click(deviceWidth / 2, deviceHeight / 2)
            sleep(yanchi1)
            let clip = images.clip(captureScreen(), cunliangWeizhi.x, cunliangWeizhi.y, cunliangWeizhi.w, cunliangWeizhi.h);
            let result = "";
            if (shibiefangshi == 0) {
                result = gmlkit.ocr(clip, "zh");
                result = result.text;
            } else if (shibiefangshi == 1) {
                result = paddle.ocrText(clip);
                if (result.length) {
                    result = result[0]
                }
            } else {
                result = gmlkit.ocr(clip, "zh");
                result = result.text;
            }
            clip.recycle();
            // 识别容错
            if (result == "") {
                log('采集中存量异常')
                guanbiFunc()
                sleep(yanchi2)
                return;
            }

            result = result.substring(2, result.length);
            if (result) {
                if (result.includes("万")) {
                    myLogFunc("资源十分充足");
                    guanbiFunc()
                    sleep(yanchi1)
                } else {
                    myLogFunc('存量:' + parseFloat(result))
                    if (parseFloat(result) < Number(storage.get("cunliangNumSy", "10"))) {
                        myLogFunc('存量不足,撤回')
                        log(parseFloat(result), storage.get("cunliangNumSy", "10"))
                        let thisImgs3 = images.read("./res/撤回.png");
                        thisImgs3 = images.scale(thisImgs3, picJizhun, picJizhunHeight)
                        let p3 = findImage(captureScreen(), thisImgs3);
                        thisImgs3.recycle();
                        if (p3) {
                            click(p3.x, p3.y);
                            sleep(yanchi1)
                            let thisImgs5 = images.read("./res/撤回确认.png");
                            thisImgs5 = images.scale(thisImgs5, picJizhun, picJizhunHeight)
                            let p5 = findImage(captureScreen(), thisImgs5);
                            thisImgs5.recycle();
                            if (p5) {
                                click(p5.x, p5.y);
                                sleep(yanchi2)
                            }
                        }
                    } else {
                        myLogFunc("资源充足");
                        guanbiFunc()
                        sleep(yanchi1)
                    }
                }
            } else {
                myLogFunc('存量信息有误')
                guanbiFunc()
                sleep(yanchi1)
            }
        }
        sleep(yanchi1)
    }
}

// 敌袭反击队伍
function fanjiduiwuFunc(params) {
    if (params.length) {
        for (let index = 0; index < params.length; index++) {
            log('反击敌袭', params[index])
            click(params[index].point.x + 15, params[index].point.y)
            sleep(yanchi2)
            let thisImgs2 = images.read("./res/fanjitaofa.png");
            thisImgs2 = images.scale(thisImgs2, picJizhun, picJizhunHeight)
            let p2 = findImage(captureScreen(), thisImgs2, { threshold: 0.85 });
            thisImgs2.recycle();
            if (p2) {
                click(p2.x + 5, p2.y + 5)
                sleep(yanchi2)
                // 英雄信息
                let thisImgs4 = images.read("./res/英雄信息.png");
                thisImgs4 = images.scale(thisImgs4, picJizhun, picJizhunHeight)
                let result = images.matchTemplate(captureScreen(), thisImgs4, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)], threshold: 0.8, max: 8 });
                thisImgs4.recycle();
                if (result.matches.length) {
                    let p4 = result.sortBy("left-right").matches[0].point;
                    sleep(yanchi)
                    click(p4.x - 109, p4.y + 168.5)
                    sleep(yanchi1)
                    // 讨伐出发
                    myLogFunc('讨伐出发')
                    let thisImgs5 = images.read("./res/讨伐按钮.png");
                    thisImgs5 = images.scale(thisImgs5, picJizhun, picJizhunHeight)
                    let p5 = findImage(captureScreen(), thisImgs5, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)] });
                    thisImgs5.recycle();
                    if (p5) {
                        log("反击讨伐按钮")
                        sleep(yanchi)
                        click(p5.x, p5.y);
                        sleep(yanchi1)
                    } else {
                        myLogFunc("行军不足!")
                        guanbiFunc()
                        let thisImgs3 = images.read("./res/别人野怪关闭.png");
                        thisImgs3 = images.scale(thisImgs3, picJizhun, picJizhunHeight)
                        let p3 = findImage(captureScreen(), thisImgs3, { threshold: 0.86 });
                        thisImgs3.recycle();
                        if (p3) {
                            myLogFunc("关闭2");
                            sleep(yanchi)
                            click(p3.x, p3.y);
                        }
                        sleep(yanchi)
                    }


                }
            } else {
                myLogFunc("未发现反击队伍")
            }
        }
    } else {
        log("错误 fanjiduiwuFunc")
    }
}


// 敌袭撤采集
function dixichecaijiFunc() {
    sleep(yanchi)
    let thisImgs = images.read("./res/caijizhong.png");
    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
    let result = images.matchTemplate(captureScreen(), thisImgs, { region: [youshangDuilie.x, youshangDuilie.y, youshangDuilie.w, youshangDuilie.h], threshold: 0.72, max: 4 });
    thisImgs.recycle();
    if (result && result.matches.length) {
        zuiduancaiji = new Date().getTime() + 120000;
        let matchRc1 = result.sortBy("left-right").matches;
        for (let index = 0; index < matchRc1.length; index++) {
            log('进入采集查看', matchRc1[index])
            click(matchRc1[index].point.x + 15, matchRc1[index].point.y)
            sleep(yanchi2)
            log('采集中资源')
            click(deviceWidth / 2, deviceHeight / 2)
            sleep(yanchi1)

            myLogFunc('敌袭,撤回')
            let thisImgs3 = images.read("./res/撤回.png");
            thisImgs3 = images.scale(thisImgs3, picJizhun, picJizhunHeight)
            let p3 = findImage(captureScreen(), thisImgs3);
            thisImgs3.recycle();
            if (p3) {
                click(p3.x, p3.y);
                sleep(yanchi1)
                let thisImgs5 = images.read("./res/撤回确认.png");
                thisImgs5 = images.scale(thisImgs5, picJizhun, picJizhunHeight)
                let p5 = findImage(captureScreen(), thisImgs5);
                thisImgs5.recycle();
                if (p5) {
                    click(p5.x, p5.y);
                    sleep(yanchi2)
                }
            } else {
                guanbiFunc();
            }

        }
        sleep(yanchi1)
    }
}

// 异常返回
function yichangFanhuiFunc(baocuo) {
    let thisImgs2 = images.read("./res/蓝底关闭.png");
    thisImgs2 = images.scale(thisImgs2, picJizhun, picJizhunHeight)
    let p2 = findImage(captureScreen(), thisImgs2, { threshold: 0.85 });
    thisImgs2.recycle();
    if (p2) {
        click(p2.x + 5, p2.y + 5)
        sleep(yanchi2)
    } else {
        let thisImgs3 = images.read("./res/首页挑战.png");
        thisImgs3 = images.scale(thisImgs3, picJizhun, picJizhunHeight)
        let p3 = findImage(captureScreen(), thisImgs3);
        thisImgs3.recycle();
        if (p3) {
            myLogFunc('在游戏首页')
            sleep(yanchi1)
            let thisImgs4 = images.read("./res/首页取消.png");
            thisImgs4 = images.scale(thisImgs4, picJizhun, picJizhunHeight)
            let p4 = findImage(captureScreen(), thisImgs4, { threshold: 0.86 });
            thisImgs4.recycle();
            if (p4) {
                log('首页取消')
                click(p4.x, p4.y);
                sleep(yanchi1)
            }
            let y = p3.y - (150 * picJizhun)
            click(p3.x, y);
            sleep(yanchi2)
            shouyejinru = true;
            // 进入世界页面
            sleep(yanchi2)
            ShijieShouyeFunc()
        } else {
            myLogFunc('按键返回' + baocuo)
            back()
        }
    }
}

// 查看联盟
function seeLianmengFunc() {
    sleep(yanchi1)
    let thisImgs = images.read("./res/联盟按钮.png");
    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
    let p = findImage(captureScreen(), thisImgs, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)], threshold: 0.82 });
    thisImgs.recycle();
    if (p) {
        myLogFunc('点击联盟')
        sleep(yanchi)
        click(p.x, p.y)
        sleep(yanchi1)
        return true;
    } else {
        myLogFunc('error联盟按钮')
        return false;
    }
}

// 联盟建筑
function lianmengjianzhuFunc() {
    sleep(yanchi)
    let thisImgs = images.read("./res/联盟建筑.png");
    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
    let p = findImage(captureScreen(), thisImgs, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)], threshold: 0.8 });
    thisImgs.recycle();
    if (p) {
        myLogFunc('点击联盟建筑')
        sleep(yanchi)
        click(p.x, p.y)
        sleep(yanchi1)
        return true;
    } else {
        myLogFunc('error联盟建筑')

        yichangFanhuiFunc("联盟建筑异常")
        sleep(yanchi1)
        seeLianmengFunc()
        sleep(yanchi2)
        lianmengjianzhuFunc()
    }
}

// 重写延迟
function rewriteDelayFunc(num) {
    myLogFunc("本机反应较慢_增加延迟时间");
    myLogFunc("原延迟基准" + delayBase);
    num = delayBase * num
    if (num > 2.5) {
        myLogFunc("触发延迟安全值，请联系管理员");
        return;
    }
    myLogFunc("新延迟基准" + num);
    storage.put("delayBase", num);
    delayBase = Number(storage.get("delayBase", "1"));
    log('delayBase', delayBase)
    let yanchiBase = 500;
    yanchi = yanchiBase * delayBase; // 点击后停顿
    yanchi1 = yanchiBase * 2 * delayBase; // 点击前停顿
    yanchi2 = yanchiBase * 4 * delayBase; // 点击后停顿
    yanchi3 = yanchiBase * 6 * delayBase; // 点击后停顿
    yanchi5 = yanchiBase * 10 * delayBase; // 点击后停顿
    log('yanchi', yanchi, yanchi1, yanchi2, yanchi3, yanchi5)
}

// 前往联盟资源
function qianwangziyuanFunc(index) {
    let thisImgs = images.read("./res/前往联盟资源.png");
    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
    let result = images.matchTemplate(captureScreen(), thisImgs, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)], threshold: 0.85, max: 3 });
    thisImgs.recycle();
    let matchRc = result.sortBy("left-right").matches;
    if (result) {
        log('前往联盟资源', matchRc.length, matchRc)
        if (matchRc.length < 2) {
            if (matchRc.length == 0) {
                yichangFanhuiFunc("前往联盟资源异常")
                return false;
            }
            let thisImgs1 = images.read("./res/建造资源.png");
            thisImgs1 = images.scale(thisImgs1, picJizhun, picJizhunHeight)
            let p1 = findImage(captureScreen(), thisImgs1, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)], threshold: 0.8 });
            thisImgs1.recycle();
            if (p1) {
                if (index == 0) {
                    myLogFunc('未建联盟资源')
                    back()
                    sleep(yanchi1)
                    return false;
                } else if (index == 1) {
                    myLogFunc('前往联仓库')
                    let p = matchRc[matchRc.length - 1].point;
                    click(p.x, p.y)
                    sleep(yanchi3)
                    click(deviceWidth / 2, ((deviceHeight / 2) - 2))
                    sleep(yanchi1)
                    return true;
                } else if (index == 2) {
                    if (matchRc.length > 1) {
                        myLogFunc('前往战备署')
                        let p = matchRc[0].point;
                        click(p.x, p.y)
                        sleep(yanchi3)
                        click(deviceWidth / 2, ((deviceHeight / 2) - 2))
                        sleep(yanchi1)
                        return true;
                    } else {
                        myLogFunc('未建设备战署')
                        back()
                        sleep(yanchi1)
                        return false;
                    }
                }
            } else {
                myLogFunc('前往联盟资源_未建仓库')
                if (index != 0) {
                    return false;
                }
                let p = matchRc[index].point;
                click(p.x, p.y)
                sleep(yanchi1)
                sleep(yanchi3)
                let thisImgs2 = images.read("./res/联盟资源.png");
                thisImgs2 = images.scale(thisImgs2, picJizhun, picJizhunHeight)
                let p2 = findImage(captureScreen(), thisImgs2);
                thisImgs2.recycle();
                if (p2) {
                    log('找到联盟资源')
                    click(deviceWidth / 2, deviceHeight / 2)
                    return true;
                } else {
                    rewriteDelayFunc(1.2)
                    sleep(yanchi2)
                    click(deviceWidth / 2, deviceHeight / 2)
                    return true;
                }
            }
        } else {
            if (index == 0) {
                myLogFunc('前往联盟资源')
                if (Boolean(storage.get("isSanguo", false))) {
                    if (matchRc.length > 2) {
                        index = 1
                    } else {
                        index = 0
                    }
                }
                let p = matchRc[index].point;
                click(p.x, p.y)
                sleep(yanchi1)
                sleep(yanchi3)
                let thisImgs2 = images.read("./res/联盟资源.png");
                thisImgs2 = images.scale(thisImgs2, picJizhun, picJizhunHeight)
                let p2 = findImage(captureScreen(), thisImgs2, { threshold: 0.85 });
                thisImgs2.recycle();
                if (p2) {
                    log('找到联盟资源')
                    click(deviceWidth / 2, ((deviceHeight / 2) - 2))
                    sleep(yanchi1)
                    return true;
                } else {
                    log('未找到联盟资源发动延迟')
                    rewriteDelayFunc(1.2)
                    sleep(yanchi2)
                    click(deviceWidth / 2, ((deviceHeight / 2) - 2))
                    sleep(yanchi1)
                    return true;
                }
            } else if (index == 1) {
                myLogFunc('前往联仓库')
                let p = matchRc[matchRc.length - 1].point;
                click(p.x, p.y)
                sleep(yanchi3)
                click(deviceWidth / 2, ((deviceHeight / 2) - 2))
                sleep(yanchi1)
                return true;
            } else if (index == 2) {
                myLogFunc('前往战备署')
                let p = matchRc[0].point;
                click(p.x, p.y)
                sleep(yanchi3)
                click(deviceWidth / 2, ((deviceHeight / 2) - 2))
                sleep(yanchi1)
                return true;
            } else {
                myLogFunc('联盟参数异常！')
                guanbiFunc();
                return false;
            }
        }
    } else {
        myLogFunc('error联盟资源')
        return false;
    }
}

// 采集流程
function cajiAnniuFunc(bloo, bloo2) {
    let thisImgs = images.read("./res/资源采集_1155_930_1337_1030.png");
    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
    let p = findImage(captureScreen(), thisImgs, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)] });
    thisImgs.recycle();
    if (p) {
        if (!bloo) {
            if (cunliangWeizhi.x == 0) {
                myLogFunc('第一次配置存量信息')
                let thisImgs = images.read("./res/存量.png");
                thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight);
                let cunliangP = findImage(captureScreen(), thisImgs, { region: [(deviceWidth / 2 - 100), 0, (deviceWidth / 2), (deviceHeight / 2)], threshold: 0.85 });
                thisImgs.recycle();
                if (cunliangP) {
                    let cunliangquyu = { x: cunliangP.x, y: cunliangP.y, w: parseInt(250 * picJizhun), h: parseInt(65 * picJizhunHeight) }
                    cunliangWeizhi = cunliangquyu;
                    log('资源存量区域对象', cunliangquyu)
                    let clip = images.clip(captureScreen(), cunliangquyu.x, cunliangquyu.y, cunliangquyu.w, cunliangquyu.h);
                    let result = "";
                    if (shibiefangshi == 0) {
                        result = gmlkit.ocr(clip, "zh");
                        result = result.text;
                    } else if (shibiefangshi == 1) {
                        result = paddle.ocrText(clip);
                        if (result.length) {
                            result = result[0]
                        }
                    } else {
                        result = gmlkit.ocr(clip, "zh");
                        result = result.text;
                    }
                    clip.recycle();
                    // 识别容错
                    if (result == "") {
                        log('读取存量异常')
                        return false;
                    }
                    storage.put("cunliangWeizhi", cunliangWeizhi);
                    result = result.substring(2, result.length);
                    if (result.includes("万")) {
                        log("十万以上资源");
                    } else {
                        if (parseFloat(result) < Number(storage.get("cunliangNum", "19999"))) {
                            myLogFunc('资源存量不足')
                            log(result, storage.get("cunliangNum", "19999"))
                            back();
                            sleep(yanchi)
                            return false;
                        } else {
                            myLogFunc('存量:' + parseFloat(result))
                        }
                        log("不是过万资源");
                    }
                }
            } else {
                log('存量位置', cunliangWeizhi)
                let clip = images.clip(captureScreen(), cunliangWeizhi.x, cunliangWeizhi.y, cunliangWeizhi.w, cunliangWeizhi.h);
                let result = "";
                if (shibiefangshi == 0) {
                    result = gmlkit.ocr(clip, "zh");
                    result = result.text;
                } else if (shibiefangshi == 1) {
                    result = paddle.ocrText(clip);
                    if (result.length) {
                        result = result[0]
                    }
                } else {
                    result = gmlkit.ocr(clip, "zh");
                    result = result.text;
                }
                clip.recycle();
                // 识别容错
                if (result == "") {
                    log('读取存量异常')
                    return false;
                }
                result = result.substring(2, result.length);
                if (result) {
                    if (result.includes("万")) {
                        log("十万以上资源");
                    } else {
                        if (parseFloat(result) < Number(storage.get("cunliangNum", "19999"))) {
                            myLogFunc('资源存量不足')
                            log(result, storage.get("cunliangNum", "19999"))
                            back();
                            sleep(yanchi)
                            return false;
                        } else {
                            myLogFunc('存量:' + parseFloat(result))
                        }
                        log("不是过万资源");
                    }
                } else {
                    myLogFunc('存量信息有误')
                }

            }
        }
        let thisImgsX = images.read("./res/采集上限.png");
        thisImgsX = images.scale(thisImgsX, picJizhun, picJizhunHeight)
        let pX = findImage(captureScreen(), thisImgsX);
        thisImgsX.recycle();
        if (pX) {
            caijiduiwu = duiwushangxian;
            click(10, (deviceHeight / 2))
            sleep(yanchi1)
            back();
            sleep(yanchi)
            return false;
        }
        myLogFunc('资源可采集', p)
        sleep(yanchi)
        click(p.x, p.y);
        sleep(yanchi1)
        return true;
    } else {
        myLogFunc("资源不可采集");
        let thisImgs = images.read("./res/世界首页.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let p = findImage(captureScreen(), thisImgs, { threshold: 0.86 });
        thisImgs.recycle();
        if (p) {
            myLogFunc('世界模式首页啊')
            return false;
        } else {
            yichangFanhuiFunc("采集按键异常")
            sleep(yanchi1)
            if (!bloo2) {
                caijiduilieFunc();
            }
            return false;
        }
    }
}

function caijiRcFunc() {
    log('查探是否可派兵')
    let thisImgsRc = images.read("./res/资源采集_1155_930_1337_1030.png");
    thisImgsRc = images.scale(thisImgsRc, picJizhun, picJizhunHeight)
    let p = findImage(captureScreen(), thisImgsRc);
    thisImgsRc.recycle();
    if (p) {
        return true
    } else {
        return false
    }
}

// 选择采集英雄
function caijiYingxiongFunc(bloo) {
    let cap = captureScreen()
    if (storage.get("caijiyouxian", "") == 0 && !bloo) {
        let thisImgs = images.read("./res/采集武将_1514_871_1649_935.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let result = images.matchTemplate(cap, thisImgs, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)], threshold: 0.8, max: 3 });
        thisImgs.recycle();
        if (result.matches.length && !storage.get("qiangzhidufen", false)) {
            let p = result.first().point;
            myLogFunc('点击采集标志武将')
            sleep(yanchi)
            click(p.x, p.y);
            sleep(yanchi1)
            // 有采集标志 判断兵力啊
            let thisImgsRc = images.read("./res/资源采集_no.png");
            thisImgsRc = images.scale(thisImgsRc, picJizhun, picJizhunHeight)
            let pRc = findImage(captureScreen(), thisImgsRc, { region: [0, 0, (deviceWidth / 2), (deviceHeight / 2)] });
            thisImgsRc.recycle();
            if (pRc) {
                myLogFunc('兵力不足')
                let thisImgsElse = images.read("./res/英雄信息.png");
                thisImgsElse = images.scale(thisImgsElse, picJizhun, picJizhunHeight)
                let resultRc = images.matchTemplate(captureScreen(), thisImgsElse, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)], threshold: 0.5, max: 8 });
                let matchRc = resultRc.sortBy("left-right").matches;
                let isChengLe = false;
                for (let index = 0; index < matchRc.length; index++) {
                    log('查探次数', index)
                    click(matchRc[index].point.x - 109, matchRc[index].point.y + 168.5);
                    sleep(yanchi1)
                    if (caijiRcFunc()) {
                        log('备用采集英雄')
                        isChengLe = true;
                        break;
                    }
                }
                if (!isChengLe) {
                    xiaobingbuzu = true;
                    myLogFunc('全体兵种不足')
                    back()
                    sleep(yanchi1)
                    back()
                    sleep(yanchi)
                }
            } else {
                log('兵力充足')
            }

        } else {
            myLogFunc('没有采集标志武将')
            myLogFunc('进入比分采集')
            let thisImgsElse = images.read("./res/英雄信息.png");
            thisImgsElse = images.scale(thisImgsElse, picJizhun, picJizhunHeight)
            let result = images.matchTemplate(cap, thisImgsElse, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)], threshold: 0.5, max: 8 });
            thisImgsElse.recycle();
            if (result.matches.length) {
                let bestMatch = {}
                let bestNumber = 0;
                result.sortBy("left-right").matches.forEach((match, indes) => {
                    if (indes >= storage.get("caijibaoliuHero", "0")) {
                        click(match.point.x - 109, match.point.y + 168.5);
                        sleep(yanchi1)
                        // 如果没有规划读取资源数据区域
                        if (yingxiongMsgWeizhi.x == 0) {
                            myLogFunc("没有配置采集数据区域")
                            let thisImgs1 = images.read("./res/资源负重.png");
                            thisImgs1 = images.scale(thisImgs1, picJizhun, picJizhunHeight)
                            let thisImgs2 = images.read("./res/资源耗时.png");
                            thisImgs2 = images.scale(thisImgs2, picJizhun, picJizhunHeight)
                            let p1 = findImage(cap, thisImgs1, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), deviceHeight], threshold: 0.8 });
                            let p2 = findImage(cap, thisImgs2, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), deviceHeight], threshold: 0.8 });
                            yingxiongMsgWeizhi.x = p1.x
                            yingxiongMsgWeizhi.y = p1.y
                            yingxiongMsgWeizhi.h = p2.y - p1.y
                            myLogFunc('采集数据区域', yingxiongMsgWeizhi)
                            storage.put("yingxiongMsgWeizhi", yingxiongMsgWeizhi);
                            yingxiongMsgWeizhi = storage.get("yingxiongMsgWeizhi", { x: 0, y: 0, w: 300, h: 0 }); // 英雄信息坐标
                        }

                        // 查看采集分和负重分做比较
                        let clip = images.clip(captureScreen(), yingxiongMsgWeizhi.x, yingxiongMsgWeizhi.y, yingxiongMsgWeizhi.w, yingxiongMsgWeizhi.h);
                        let orcRes = ""
                        let fraction = 0
                        if (shibiefangshi == 0) {
                            orcRes = gmlkit.ocr(clip, "zh");
                            if (orcRes.children.length > 1) {
                                fraction = orcRes.children[1].text.split(': ')[1]
                                fraction = parseFloat(fraction)
                            }
                        } else if (shibiefangshi == 1) {
                            orcRes = paddle.ocrText(clip);
                            fraction = res[1].text.split('：')[1]
                            fraction = parseFloat(fraction)
                        } else {
                            orcRes = gmlkit.ocr(clip, "zh");
                            if (orcRes.children.length > 1) {
                                fraction = orcRes.children[1].text.split(': ')[1]
                                fraction = parseFloat(fraction)
                            }
                        }
                        clip.recycle();
                        // 记录最大分和英雄位置
                        if (fraction > bestNumber) {
                            bestNumber = fraction;
                            bestMatch = match;
                        }
                    } else {
                        myLogFunc('跳过保留英雄')
                    }
                    sleep(yanchi)
                });

                sleep(yanchi)
                myLogFunc('采集分最高：' + bestNumber)
                if (bestMatch.point) {
                    click(bestMatch.point.x - 109, bestMatch.point.y + 168.5);
                    sleep(yanchi1)
                }

                let thisImgsRc = images.read("./res/资源采集_no.png");
                thisImgsRc = images.scale(thisImgsRc, picJizhun, picJizhunHeight)
                let p = findImage(captureScreen(), thisImgsRc, { region: [0, 0, (deviceWidth / 2), (deviceHeight / 2)] });
                thisImgsRc.recycle();
                if (p) {
                    myLogFunc('兵力不足')
                    let matchRc = result.sortBy("left-right").matches;
                    let isChengLe = false;
                    for (let index = 0; index < matchRc.length; index++) {
                        click(matchRc[index].point.x - 109, matchRc[index].point.y + 168.5);
                        sleep(yanchi1)
                        if (caijiRcFunc()) {
                            log('备用采集英雄')
                            isChengLe = true;
                            break;
                        }
                    }
                    if (!isChengLe) {
                        xiaobingbuzu = true;
                        myLogFunc('全体兵种不足')
                        back()
                        sleep(yanchi1)
                        back()
                        sleep(yanchi)
                    }
                }
            } else {
                myLogFunc('界面异常！')
                chaoguocaiFunc()
            }
        }
    } else {
        let thisImgs = images.read("./res/负重武将_568_869_692_937.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let result = images.matchTemplate(cap, thisImgs, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)], threshold: 0.8, max: 2 });
        thisImgs.recycle();
        if (result.matches.length && !storage.get("qiangzhidufen", false)) {
            myLogFunc('负重武将')
            let p = result.first().point;
            click(p.x, p.y);
            sleep(yanchi1)
            // 有采集标志 判断兵力啊
            let thisImgsRc = images.read("./res/资源采集_no.png");
            thisImgsRc = images.scale(thisImgsRc, picJizhun, picJizhunHeight)
            let pRc = findImage(captureScreen(), thisImgsRc, { region: [0, 0, (deviceWidth / 2), (deviceHeight / 2)] });
            thisImgsRc.recycle();
            if (pRc) {
                myLogFunc('兵力不足')
                let thisImgsElse = images.read("./res/英雄信息.png");
                thisImgsElse = images.scale(thisImgsElse, picJizhun, picJizhunHeight)
                let resultRc = images.matchTemplate(captureScreen(), thisImgsElse, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)], threshold: 0.5, max: 8 });
                let matchRc = resultRc.sortBy("left-right").matches;
                let isChengLe = false;
                for (let index = 0; index < matchRc.length; index++) {
                    click(matchRc[index].point.x - 109, matchRc[index].point.y + 168.5);
                    sleep(yanchi1)
                    if (caijiRcFunc()) {
                        log('备用负重英雄')
                        isChengLe = true;
                        break;
                    }
                }
                if (!isChengLe) {
                    xiaobingbuzu = true;
                    myLogFunc('全体兵种不足')
                    back()
                    sleep(yanchi1)
                    back()
                    sleep(yanchi)
                }
            }
        } else {
            myLogFunc('没有负重标志武将')
            myLogFunc('进入比分采集')

            let thisImgs = images.read("./res/英雄信息.png");
            thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
            let result = images.matchTemplate(cap, thisImgs, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)], threshold: 0.5, max: 8 });
            thisImgs.recycle();
            if (result.matches.length) {
                let bestMatch = {}
                let bestNumber = 0;
                result.sortBy("left-right").matches.forEach(match => {
                    click(match.point.x - 109, match.point.y + 168.5);
                    sleep(yanchi)
                    // 如果没有规划读取资源数据区域
                    if (yingxiongMsgWeizhi.x == 0) {
                        myLogFunc("没有配置采集数据区域")
                        let thisImgs1 = images.read("./res/资源负重.png");
                        thisImgs1 = images.scale(thisImgs1, picJizhun, picJizhunHeight)
                        let thisImgs2 = images.read("./res/资源耗时.png");
                        thisImgs2 = images.scale(thisImgs2, picJizhun, picJizhunHeight)
                        let p1 = findImage(cap, thisImgs1, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), deviceHeight], threshold: 0.8 });
                        let p2 = findImage(cap, thisImgs2, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), deviceHeight], threshold: 0.8 });
                        yingxiongMsgWeizhi.x = p1.x
                        yingxiongMsgWeizhi.y = p1.y
                        yingxiongMsgWeizhi.h = p2.y - p1.y
                        myLogFunc('采集数据区域', yingxiongMsgWeizhi)
                        storage.put("yingxiongMsgWeizhi", yingxiongMsgWeizhi);
                        yingxiongMsgWeizhi = storage.get("yingxiongMsgWeizhi", { x: 0, y: 0, w: 300, h: 0 }); // 英雄信息坐标
                    }

                    // 查看采集分和负重分做比较
                    let clip = images.clip(captureScreen(), yingxiongMsgWeizhi.x, yingxiongMsgWeizhi.y, yingxiongMsgWeizhi.w, yingxiongMsgWeizhi.h);
                    let orcRes = ""
                    let fraction = 0
                    if (shibiefangshi == 0) {
                        orcRes = gmlkit.ocr(clip, "zh");
                        if (orcRes.children.length > 1) {
                            fraction = orcRes.children[1].text.split(': ')[1]
                            fraction = parseFloat(fraction)
                        }
                    } else if (shibiefangshi == 1) {
                        orcRes = paddle.ocrText(clip);
                        fraction = res[1].text.split('：')[1]
                        fraction = parseFloat(fraction)
                    } else {
                        orcRes = gmlkit.ocr(clip, "zh");
                        if (orcRes.children.length > 1) {
                            fraction = orcRes.children[1].text.split(': ')[1]
                            fraction = parseFloat(fraction)
                        }
                    }
                    clip.recycle();
                    // myLogFunc('负重：',fraction)
                    if (fraction > bestNumber) {
                        bestNumber = fraction;
                        bestMatch = match;
                    }
                    sleep(yanchi)
                });

                sleep(yanchi)
                myLogFunc('负重最高：' + bestNumber)
                click(bestMatch.point.x - 109, bestMatch.point.y + 168.5);
                sleep(yanchi1)

                let thisImgsRc = images.read("./res/资源采集_no.png");
                thisImgsRc = images.scale(thisImgsRc, picJizhun, picJizhunHeight)
                let p = findImage(captureScreen(), thisImgsRc, { region: [0, 0, (deviceWidth / 2), (deviceHeight / 2)] });
                thisImgsRc.recycle();
                if (!p) {
                    myLogFunc('兵力不足')
                    let matchRc = result.sortBy("left-right").matches;
                    let isChengLe = false;
                    for (let index = 0; index < matchRc.length; index++) {
                        click(matchRc[index].point.x - 109, matchRc[index].point.y + 168.5);
                        sleep(yanchi1)
                        if (caijiRcFunc()) {
                            log('备用采集英雄')
                            isChengLe = true;
                            break;
                        }
                    }
                    if (!isChengLe) {
                        xiaobingbuzu = true;
                        myLogFunc('全体兵种不足')
                        back()
                        sleep(yanchi1)
                        back()
                        sleep(yanchi)
                    }
                }

            } else {
                myLogFunc('界面异常！')
                chaoguocaiFunc()
            }
        }
    }
}

// 界面异常处理 -- 超过采集
function chaoguocaiFunc() {
    let thisImgsRc = images.read("./res/蓝底关闭.png");
    thisImgsRc = images.scale(thisImgsRc, picJizhun, picJizhunHeight)
    let p = findImage(captureScreen(), thisImgsRc, { threshold: 0.85 });
    thisImgsRc.recycle();
    if (p) {
        // 超过采集
        click(p.x, p.y)
        log("超过采集")
        myLogFunc('关闭')
        sleep(yanchi1)
        chaoguocaiFunc()
        return true
    } else {
        log('不是超出采集')
        caijiduilieFunc(true);
        return false
    }
}

// 采集资源出发完成
function caijiChufaFunc(bloo) {
    let thisImgs = images.read("./res/资源采集_1155_930_1337_1030.png");
    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
    let result = images.matchTemplate(captureScreen(), thisImgs, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)], threshold: 0.86, max: 2 });
    thisImgs.recycle();
    if (result.matches.length) {
        if (result.matches.length == 1) {
            let p = result.matches[0].point;
            sleep(yanchi)
            click(p.x, p.y + 5);
            sleep(yanchi3)
            log('采集出发,重读队列')
            caijiduilieFunc();
            sleep(yanchi1)
        } else {
            result.sortBy("left-right").matches.forEach((match, index) => {
                if (index == 0) {
                    log('match', match)
                    let p = match.point;
                    sleep(yanchi)
                    click(p.x, p.y + 5);
                    sleep(yanchi3)
                    log('采集出发1,重读队列')
                    caijiduilieFunc();
                    sleep(yanchi1)
                }
            })
        }
    }

    if (!bloo) {
        if (shangciweizhi.x == 0) {
            let thisImgs1 = images.read("./res/上次位置.png");
            thisImgs1 = images.scale(thisImgs1, picJizhun, picJizhunHeight)
            let p1 = findImage(captureScreen(), thisImgs1);
            thisImgs1.recycle();
            if (p1) {
                sleep(yanchi)
                let newObj = { x: p1.x, y: p1.y };
                storage.put("shangciweizhi", newObj);
                shangciweizhi = storage.get("shangciweizhi", { x: 0, y: 0 });
                click(p1.x, p1.y);
                sleep(yanchi5)
            }
        } else {
            click(shangciweizhi.x, shangciweizhi.y);
            sleep(yanchi5)
        }
    }

    return
}

// 查看世界地图
function seeShijieditu() {
    let thisImgs = images.read("./res/世界地图按钮.png");
    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
    let p = findImage(captureScreen(), thisImgs);
    thisImgs.recycle();
    if (p) {
        myLogFunc('打开世界地图')
        click(p.x, p.y)
        sleep(yanchi1)



        // 如果是第一次则配置地图
        if (xiaodituPosit.x == 0) {
            myLogFunc('第一次配置小地图参数')
            sleep(yanchi1)
            let thisImgs1 = null;
            if (Boolean(storage.get("isSanguo", false))) {
                thisImgs1 = images.read("./res/小地图1.png");
            } else {
                thisImgs1 = images.read("./res/小地图.png");
            }
            thisImgs1 = images.scale(thisImgs1, picJizhun, picJizhunHeight)
            let p1 = findImage(captureScreen(), thisImgs1, { threshold: 0.9 });
            thisImgs1.recycle();
            if (p1) {
                log('小地图起点坐标', p1)
                let newObj = { x: p1.x, y: p1.y };
                storage.put("xiaodituPosit", newObj);
                xiaodituPosit = storage.get("xiaodituPosit", { x: 0, y: 0 });
            } else {
                toastLog("小地图信息异常")
                exit()
            }
        }


        let thisImgs1 = null;
        if (Boolean(storage.get("isSanguo", false))) {
            thisImgs1 = images.read("./res/小地图1.png");
        } else {
            thisImgs1 = images.read("./res/小地图.png");
        }
        thisImgs1 = images.scale(thisImgs1, picJizhun, picJizhunHeight)
        let p1 = findImage(captureScreen(), thisImgs1, { threshold: 0.85 });
        thisImgs1.recycle();
        if (!p1) {
            myLogFunc('打开小地图失败')
            xiaojinglingJc();
        }

    } else {
        myLogFunc('打开地图失败')
        sleep(yanchi)
        yichangFanhuiFunc("世界地图异常")
        sleep(yanchi1)
        seeShijieditu()
    }
}

// 查看指定位置资源
function seeZiyuanFunc(iszhiding) {
    sleep(yanchi3)
    let thisImgs = images.read("./res/ziyuan.png");
    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
    let thiscap = captureScreen()
    let myThre = 0.7;
    if (deviceHeight == 1080) {
        myThre = 0.75;
    } else {
        myThre = 0.71;
    }
    let result = images.matchTemplate(thiscap, thisImgs, { region: [(deviceWidth / 2 - 200), (deviceHeight / 2 - 150), 400, 300], threshold: myThre, max: 8 });
    thisImgs.recycle();
    if (result.matches.length) {
        log('资源：', result)
        if (result.matches.length == 1) {
            myLogFunc('前往采集点')
            let p = result.matches[0].point;
            click(p.x, p.y)
        } else {
            myLogFunc('区域多个采集点')
            let points = result.sortBy("left-right").points
            let lastTimeXy = { x: 0, y: 0 }
            let firstPosition = { x: 0, y: 0 }
            // myLogFunc('序列化坐标集', points)
            for (let index = 0; index < points.length; index++) {
                let match = points[index];
                log('资源', index, match)
                let juli = Math.abs(lastTimeXy.x - match.x)
                let juliY = Math.abs(lastTimeXy.y - match.y)
                if (juli < 100 && juliY < 5) {
                    myLogFunc('跳过同一个矿')
                    continue;
                }
                sleep(yanchi)
                click(match.x + 1, match.y - 1)
                lastTimeXy.x = match.x;
                lastTimeXy.y = match.y;

                sleep(yanchi2)
                // 如果是找点采集
                if (iszhiding) {
                    // 首次配置资源坐标位置
                    if (ziyuanZuobianWeizhi.x == 0) {
                        myLogFunc('首次配置资源坐标位置')
                        let thisImgs1 = images.read("./res/坐标背景图.png");
                        thisImgs1 = images.scale(thisImgs1, picJizhun, picJizhunHeight)
                        let p1 = findImage(captureScreen(), thisImgs1, { region: [0, 0, (deviceWidth / 2), deviceHeight], threshold: 0.8 });
                        thisImgs1.recycle();
                        log("p1", p1)
                        if (p1) {
                            myLogFunc('资源坐标位置配置完成')
                            ziyuanZuobianWeizhi.x = p1.x + 50
                            ziyuanZuobianWeizhi.y = p1.y
                            storage.put("ziyuanZuobianWeizhi", ziyuanZuobianWeizhi);
                        } else {
                            log('资源坐标位置配置失败！')
                        }
                    }
                    sleep(yanchi2)
                    log("资源坐标位置", ziyuanZuobianWeizhi.x, ziyuanZuobianWeizhi.y)
                    let clip = images.clip(captureScreen(), ziyuanZuobianWeizhi.x, ziyuanZuobianWeizhi.y, ziyuanZuobianWeizhi.w, ziyuanZuobianWeizhi.h);
                    let orcRes = "";
                    if (shibiefangshi == 0) {
                        orcRes = paddle.ocrText(clip);
                        orcRes = orcRes[0]
                    } else if (shibiefangshi == 1) {
                        orcRes = paddle.ocrText(clip);
                        orcRes = orcRes[0];
                    } else {
                        orcRes = gmlkit.ocr(clip, "zh");
                        orcRes = orcRes.text;
                    }
                    clip.recycle();
                    log("坐标截取", orcRes)
                    // 如果坐标就是寻找的坐标可以跳出循环了
                    if (orcRes && orcRes != "" && orcRes != "undefined") {
                        firstPosition.x = match.x;
                        firstPosition.y = match.y;

                        let xy = orcRes;
                        myLogFunc('坐标匹配', xy)
                        let xy0 = xy[0]
                        if (isNaN(xy0)) {
                            if (xy.includes('(') || xy.includes('（')) {
                                xy = xy.substring(1, xy.length)
                            }
                        }
                        let xy3 = xy[xy.length]
                        if (isNaN(xy3)) {
                            if (xy.includes(')') || xy.includes('）')) {
                                xy = xy.substring(0, xy.length - 1)
                            }
                        }
                        xy = xy.replace("口", "0");
                        xy = xy.replace("日", "8");
                        let douhao = ',';
                        if (xy.includes('，')) {
                            douhao = '，';
                        }
                        if (xy.includes('.')) {
                            douhao = '.';
                        }
                        let xyArr = xy.split(douhao)
                        log('xyArr', xyArr)
                        if (isNaN(xyArr[0]) || isNaN(xyArr[1])) {
                            if (shibiefangshi == 0) {
                                myLogFunc("更换算法匹配坐标")
                                sleep(yanchi)
                                let clip1 = images.clip(captureScreen(), ziyuanZuobianWeizhi.x, ziyuanZuobianWeizhi.y, ziyuanZuobianWeizhi.w, ziyuanZuobianWeizhi.h);
                                let orcRes1 = "";
                                orcRes1 = gmlkit.ocr(clip1, "zh");
                                orcRes1 = orcRes1.text;

                                clip1.recycle();
                                log("坐标截取", orcRes1)
                                // 如果坐标就是寻找的坐标可以跳出循环了
                                if (orcRes1 != "") {
                                    firstPosition.x = match.x;
                                    firstPosition.y = match.y;

                                    let xy = orcRes1;
                                    myLogFunc('坐标匹配', xy)
                                    let xy0 = xy[0]
                                    if (isNaN(xy0)) {
                                        if (xy.includes('(') || xy.includes('（')) {
                                            xy = xy.substring(1, xy.length)
                                        }
                                    }
                                    let xy3 = xy[xy.length]
                                    if (isNaN(xy3)) {
                                        if (xy.includes(')') || xy.includes('）')) {
                                            xy = xy.substring(0, xy.length - 1)
                                        }
                                    }
                                    xy = xy.replace("口", "0");
                                    xy = xy.replace("日", "8");
                                    let douhao = ',';
                                    if (xy.includes('，')) {
                                        douhao = '，';
                                    }
                                    if (xy.includes('.')) {
                                        douhao = '.';
                                    }
                                    let xyArr = xy.split(douhao)
                                    log('谷歌xyArr', xyArr)
                                    if (toCaijiList[0].x == xyArr[0] && toCaijiList[0].y == xyArr[1]) {
                                        myLogFunc('找到资源')
                                        firstPosition.x = 0;
                                        firstPosition.y = 0;
                                        break;
                                    }
                                }
                            }
                        } else if (toCaijiList[0].x == xyArr[0] && toCaijiList[0].y == xyArr[1]) {
                            myLogFunc('找到资源')
                            firstPosition.x = 0;
                            firstPosition.y = 0;
                            break;
                        }
                    } else {
                        log('坐标截取异常')
                    }
                    sleep(yanchi3)
                    guanbiFunc()
                }

            }

            // 如果循环一圈因为坐标识别问题导致失败，则默认第一个坐标
            if (firstPosition.x != 0) {
                myLogFunc('备用坐标', firstPosition.x, firstPosition.x)
                sleep(yanchi)
                click(firstPosition.x, firstPosition.y)
                sleep(yanchi1)
            }

            sleep(yanchi1)
        }
        return true;
    } else {
        myLogFunc('区域资源不可采集')
        return false;
    }
}

// 通用关闭
function guanbiFunc(cap) {
    let thisImgs2 = images.read("./res/蓝底关闭.png");
    thisImgs2 = images.scale(thisImgs2, picJizhun, picJizhunHeight)
    let p2 = cap ? findImage(cap, thisImgs2) : findImage(captureScreen(), thisImgs2);
    thisImgs2.recycle();
    if (p2) {
        myLogFunc('关闭')
        click(p2.x + 5, p2.y + 5)
        sleep(yanchi1)
    }
}

// 联盟资源关闭
function lmzyGuanbiFunc(cap) {
    let thisImgs2 = images.read("./res/联盟资源关闭.png");
    thisImgs2 = images.scale(thisImgs2, picJizhun, picJizhunHeight)
    let p2 = cap ? findImage(cap, thisImgs2, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), (deviceHeight / 2)] }) : findImage(captureScreen(), thisImgs2, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), (deviceHeight / 2)] });
    thisImgs2.recycle();
    if (p2) {
        myLogFunc('关闭')
        click(p2.x + 5, p2.y + 5)
        sleep(yanchi1)
    }
}

// 屏幕资源采集
function toAllZiyuanFunc(sahngciweizhi) {
    log('采集队伍数量', caijiduiwu, duiwushangxian)
    if (caijiduiwu < duiwushangxian) {
        log('可以进入采集')
        sleep(yanchi3)
        let thisImgs = images.read("./res/ziyuan.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let thiscap = captureScreen()
        let myThre = 0.7;
        if (deviceHeight == 1080) {
            myThre = 0.7;
        } else {
            myThre = 0.66;
        }
        let result = images.matchTemplate(thiscap, thisImgs, { region: [100 * picJizhun, 190 * picJizhunHeight, (deviceWidth - 200 * picJizhun), (deviceHeight - 200 * picJizhunHeight)], threshold: myThre, max: 10 });
        thisImgs.recycle();
        if (result.matches.length) {
            log('资源列表：', result)
            if (result.matches.length == 1) {
                myLogFunc('独立资源')
                let p = result.matches[0].point;
                if (!caijiaClick(p.x, p.y - (50 * picJizhun))) {
                    return
                }
                sleep(yanchi2)
                if (cajiAnniuFunc()) {
                    sleep(yanchi2)
                    caijiYingxiongFunc()
                    sleep(yanchi2)
                    if (!xiaobingbuzu) {
                        caijiChufaFunc(sahngciweizhi)
                        sleep(yanchi2)
                    }

                }
            } else {
                myLogFunc('多个采集点')
                let points = result.sortBy("left-right").points;
                let lastTimeXy = { x: 0, y: 0 }
                for (let index = 0; index < points.length; index++) {
                    if (caijiduiwu >= duiwushangxian) {
                        myLogFunc('采集队伍已全部派出')
                        break;
                    }
                    let match = points[index];
                    log('资源', index, match)
                    let juli = Math.abs(lastTimeXy.x - match.x)
                    let juliY = Math.abs(lastTimeXy.y - match.y)
                    if (juli < 100 && juliY < 5) {
                        myLogFunc('跳过同一个矿')
                        continue;
                    }
                    sleep(yanchi)
                    if (!caijiaClick(match.x, match.y - (50 * picJizhun))) {
                        return
                    }
                    lastTimeXy.x = match.x;
                    lastTimeXy.y = match.y;
                    sleep(yanchi2)
                    if (cajiAnniuFunc()) {
                        sleep(yanchi2)

                        caijiYingxiongFunc()
                        sleep(yanchi2)
                        if (!xiaobingbuzu) {
                            caijiChufaFunc(sahngciweizhi)
                            sleep(yanchi2)
                        }

                    } else {
                        log('资源位置变化')
                        continue;
                    }
                }
            }
        } else {
            myLogFunc('区域资源不可采集')

        }
    }
    log('完成当前屏幕采集')
    return caijiduiwu;
}

// 去采集 - 增加安全区域控制
function caijiaClick(x, y) {
    if (x < (500 * picJizhun) && y < (250 * picJizhun)) {
        myLogFunc('安全区限制')
        return false;
    }
    if (x > (1008 * picJizhun) && y < (218 * picJizhun)) {
        myLogFunc('安全区限制')
        return false;
    }
    click(x, y)
    return true;
}

// 采集打野 - 增加安全区域控制
function dayeClick(x, y) {
    if (x < (400 * picJizhun) && y < (250 * picJizhun)) {
        myLogFunc('安全区限制')
        return false;
    }
    if (x > (1008 * picJizhun) && y < (218 * picJizhun)) {
        myLogFunc('安全区限制')
        return false;
    }

    if (Boolean(storage.get("fangqiangye", false))) {
        let x1 = (x - (50 * picJizhun)) > 0 ? (x - (50 * picJizhun)) : 0;
        let y1 = (y - (100 * picJizhun)) > 0 ? (y - (100 * picJizhun)) : 0;
        let x2 = (deviceWidth - x1) > (140 * picJizhun) ? (140 * picJizhun) : (deviceWidth - x1);
        let y2 = 100 * picJizhun;
        var point = findColor(captureScreen(), "#4ABA5A", { region: [x1, y1, x2, y2] });
        if (point) {
            myLogFunc('野怪已被标记')
            log("打野颜色，坐标为(" + point.x + ", " + point.y + ")");
            return false;
        }
    }
    click(x + 1, y - 10)
    return true;
}

// 扫描打野方法
function saomiaodayeFunc() {
    // 返回自己主城
    fanhuizhuchengFunc();
    // 打野队伍查看
    dayeduilieFunc()
    myLogFunc("进行扫描打野")
    // 主城区域野怪
    myLogFunc("主城区野怪扫描")
    yeguaisaomiaoFunc(true)
    // 附近野怪扫描
    if (Boolean(storage.get("centerZhucheng", true))) {
        myLogFunc('附近野怪扫描')
        // 执行上下左右 上
        for (let index = 0; index < Number(storage.get("centerNPing", "1")); index++) {
            swipeRandom(deviceWidth * 0.5, deviceHeight * 0.5, deviceWidth * 0.5, deviceHeight * 0.8, 1000);
            sleep(yanchi3)
            yeguaisaomiaoFunc()
        }
        // 返回自己主城
        fanhuizhuchengFunc();
        // 执行上下左右 下
        for (let index = 0; index < Number(storage.get("centerNPing", "1")); index++) {
            swipeRandom(deviceWidth * 0.5, deviceHeight * 0.5, deviceWidth * 0.5, deviceHeight * 0.2, 1000);
            sleep(yanchi3)
            yeguaisaomiaoFunc()
        }
        // 返回自己主城
        fanhuizhuchengFunc();
        // 执行上下左右 左
        for (let index = 0; index < Number(storage.get("centerNPing", "1")); index++) {
            swipeRandom(deviceWidth * 0.5, deviceHeight * 0.5, (deviceWidth - (350 * picJizhun)), deviceHeight * 0.5, 2000);
            sleep(yanchi3)
            yeguaisaomiaoFunc()
        }
        // 返回自己主城
        fanhuizhuchengFunc();
        // 执行上下左右 右
        for (let index = 0; index < Number(storage.get("centerNPing", "1")); index++) {
            swipeRandom(deviceWidth * 0.5, deviceHeight * 0.5, (350 * picJizhun), deviceHeight * 0.5, 2000);
            sleep(yanchi3)
            yeguaisaomiaoFunc()
        }
        // 返回自己主城
        fanhuizhuchengFunc();
        myLogFunc("附近扫描完成")
    }
    // 采集点附近打野
    if (Boolean(storage.get("caijiquyuDy", false))) {
        myLogFunc("采集点野怪扫描")
        for (let index = 0; index < toCaijiList.length; index++) {
            let element = toCaijiList[index];
            log(element)
            sleep(yanchi)
            seeShijieditu()
            sleep(yanchi1)
            goXyFunc(element.x, element.y)
            sleep(yanchi3)
            yeguaisaomiaoFunc()
            sleep(yanchi1)
        }
        myLogFunc("采集点附近扫描完成")
    }
    // 查看世界地图
    if (Boolean(storage.get("zuoshang", false))) {
        myLogFunc("联盟打野-左上")
        for (let index = 0; index < zuoshangList.length; index++) {
            if (index < lmNontinue) {
                continue;
            }
            let element = zuoshangList[index];
            log(element)
            sleep(yanchi)
            seeShijieditu()
            sleep(yanchi1)
            goXyFunc(element.x, element.y)
            sleep(yanchi3)
            yeguaisaomiaoFunc()
            sleep(yanchi1)
        }
    }
    if (Boolean(storage.get("zuozhong", false))) {
        myLogFunc("联盟打野-左中")
        for (let index = 0; index < zuozhongList.length; index++) {
            if (index < lmNontinue) {
                continue;
            }
            let element = zuozhongList[index];
            log(element)
            sleep(yanchi)
            seeShijieditu()
            sleep(yanchi1)
            goXyFunc(element.x, element.y)
            sleep(yanchi3)
            yeguaisaomiaoFunc()
            sleep(yanchi1)
        }
    }
    if (Boolean(storage.get("zuoxia", false))) {
        myLogFunc("联盟打野-左下")
        for (let index = 0; index < zuoxiaList.length; index++) {
            if (index < lmNontinue) {
                continue;
            }
            let element = zuoxiaList[index];
            log(element)
            sleep(yanchi)
            seeShijieditu()
            sleep(yanchi1)
            goXyFunc(element.x, element.y)
            sleep(yanchi3)
            yeguaisaomiaoFunc()
            sleep(yanchi1)
        }
    }
    if (Boolean(storage.get("youshang", false))) {
        myLogFunc("联盟打野-右上")
        for (let index = 0; index < youshangList.length; index++) {
            if (index < lmNontinue) {
                continue;
            }
            let element = youshangList[index];
            log(element, index)
            sleep(yanchi)
            seeShijieditu()
            sleep(yanchi1)
            goXyFunc(element.x, element.y)
            sleep(yanchi3)
            yeguaisaomiaoFunc()
            sleep(yanchi1)
        }
    }
    if (Boolean(storage.get("youzhong", false))) {
        myLogFunc("联盟打野-右中")
        for (let index = 0; index < youzhongList.length; index++) {
            if (index < lmNontinue) {
                continue;
            }
            let element = youzhongList[index];
            log(element)
            sleep(yanchi)
            seeShijieditu()
            sleep(yanchi1)
            goXyFunc(element.x, element.y)
            sleep(yanchi3)
            yeguaisaomiaoFunc()
            sleep(yanchi1)
        }
    }
    if (Boolean(storage.get("youxia", false))) {
        myLogFunc("联盟打野-右下")
        for (let index = 0; index < youxiaList.length; index++) {
            if (index < lmNontinue) {
                continue;
            }
            let element = youxiaList[index];
            log(element)
            sleep(yanchi)
            seeShijieditu()
            sleep(yanchi1)
            goXyFunc(element.x, element.y)
            sleep(yanchi3)
            yeguaisaomiaoFunc()
            sleep(yanchi1)
        }
    }
    // 方形区域打野
    if (Boolean(storage.get("changfangxingDy", false))) {
        fangxingquyuDyFunc();
    }
}

// 格式化打野时间
function extractNumbers(str) {
    let result = [];
    let num = '';
    for (let i = 0; i < str.length; i++) {
        if (/^\d$/.test(str[i])) {
            num += str[i];
        } else if (num !== '') {
            if (num.length == 4) {
                let firstTwoChars = num.substring(0, 2);
                let lastTwoChars = num.substring(num.length - 2);
                result.push(Number(firstTwoChars));
                result.push(Number(lastTwoChars));
                num = '';
            } else {
                result.push(Number(num));
                num = '';
            }

        }
    }
    if (num !== '') {
        result.push(Number(num));
    }
    return result;
}

// 打野队列1
function dayeduilieFunc(fanhui) {
    if (yuanbaoweizhi.y == 0) {
        myLogFunc('第一次滑动参数')
        sleep(yanchi1)
        let thisImgs = images.read("./res/元宝.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let p = findImage(captureScreen(), thisImgs, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), (deviceHeight / 2)], threshold: 0.86 });
        thisImgs.recycle();
        if (p) {
            log('滑动元宝位置')
            let newObj = { x: p.x, y: p.y };
            storage.put("yuanbaoweizhi", newObj);
            yuanbaoweizhi = storage.get("yuanbaoweizhi", { x: 2020, y: 0 });
            swipe(yuanbaoweizhi.x, youshangDuilie.y, (yuanbaoweizhi.x + (200 * picJizhun)), youshangDuilie.y, 500)
            sleep(yanchi)
        }
    } else {
        log('滑动检测位置')
        swipe(yuanbaoweizhi.x, youshangDuilie.y, (yuanbaoweizhi.x + (200 * picJizhun)), youshangDuilie.y, 500)
        sleep(yanchi)
    }
    let captureScreenTT = captureScreen();
    let thisImgs = images.read("./res/taofa.png");
    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
    let result = images.matchTemplate(captureScreenTT, thisImgs, { region: [youshangDuilie.x, youshangDuilie.y, youshangDuilie.w, youshangDuilie.h], threshold: 0.72, max: 4 });
    thisImgs.recycle();
    log("result", result)
    if (result && result.matches.length) {
        dayeduiwu = result.matches.length;
        if (dayeduiwu <= 1) {
            myLogFunc('可派出打野')
        } else {
            myLogFunc('存在讨伐队伍' + dayeduiwu)
        }
    } else {
        dayeduiwu = 0;
    }
    if (Boolean(storage.get("openDixi", false)) && dixiTishi) {
        let thisImgsNs = images.read("./res/dixitishi.png");
        thisImgsNs = images.scale(thisImgsNs, picJizhun, picJizhunHeight)
        let pNs = images.matchTemplate(captureScreenTT, thisImgsNs, { region: [youshangDuilie.x, youshangDuilie.y, youshangDuilie.w, youshangDuilie.h], threshold: 0.85 });
        thisImgsNs.recycle();
        if (pNs.matches.length) {
            dixiTishiFunc(pNs.matches)
        }
    }
    if (fanhui) {
        if (shibiefangshi == 0) {
            let clip = images.clip(captureScreen(), youshangDuilie.x, youshangDuilie.y + (20 * picJizhun), youshangDuilie.w, youshangDuilie.h);
            let result = gmlkit.ocr(clip, "zh");
            clip.recycle();
            result = result.text;
            log("时间数据", result)
            result = extractNumbers(result)
            log("时间数据1", result)
            let myLength = parseInt(result.length / 3)
            let restartTime = 0;
            for (let index = 0; index < myLength; index++) {
                let shortest = formatGameTime1(result[index * 3], result[(index * 3) + 1], result[(index * 3) + 2]);
                if (restartTime == 0) {
                    restartTime = shortest;
                }
                if (shortest < restartTime && shortest != 0) {
                    myLogFunc('较短时间:' + parseInt(shortest / 1000) + "秒")
                    restartTime = shortest;
                }
            }
            return restartTime;
        } else if (shibiefangshi == 1) {
            let clip = images.clip(captureScreen(), youshangDuilie.x, youshangDuilie.y, youshangDuilie.w, youshangDuilie.h);
            let result = paddle.ocrText(clip);
            clip.recycle();
            let restartTime = 0;
            for (let index = 0; index < result.length; index++) {
                let element = result[index];
                if (element.includes(':')) {
                    let shortest = formatGameTime(element);
                    if (restartTime == 0) {
                        restartTime = shortest;
                        log('restartTime', restartTime)
                    }
                    if (shortest < restartTime && shortest != 0) {
                        myLogFunc('较短时间:' + element)
                        restartTime = shortest;
                    }
                }
            }
            return restartTime;
        } else {
            let clip = images.clip(captureScreen(), youshangDuilie.x, youshangDuilie.y + (20 * picJizhun), youshangDuilie.w, youshangDuilie.h);
            let result = gmlkit.ocr(clip, "zh");
            clip.recycle();
            result = result.text;
            log("时间数据", result)
            result = extractNumbers(result)
            log("时间数据1", result)
            let myLength = parseInt(result.length / 3)
            let restartTime = 0;
            for (let index = 0; index < myLength; index++) {
                let shortest = formatGameTime1(result[index * 3], result[(index * 3) + 1], result[(index * 3) + 2]);
                if (restartTime == 0) {
                    restartTime = shortest;
                }
                if (shortest < restartTime && shortest != 0) {
                    myLogFunc('较短时间:' + parseInt(shortest / 1000) + "秒")
                    restartTime = shortest;
                }
            }
            return restartTime;
        }


    }
}


// 最短采集时间
function zuiduancaijiFunc() {
    if (shibiefangshi == 0) {
        let clip = images.clip(captureScreen(), youshangDuilie.x, youshangDuilie.y + (20 * picJizhun), youshangDuilie.w, youshangDuilie.h);
        let result = gmlkit.ocr(clip, "zh");
        clip.recycle();
        result = result.text;
        log("时间数据!", result)
        result = extractNumbers(result)
        log("时间数据@", result)
        let myLength = parseInt(result.length / 3)
        let restartTime = 0;
        for (let index = 0; index < myLength; index++) {
            let shortest = formatGameTime1(result[index * 3], result[(index * 3) + 1], result[(index * 3) + 2]);
            if (restartTime == 0) {
                restartTime = shortest;
            }
            if (shortest < restartTime && shortest != 0) {
                restartTime = shortest;
            }
        }
        myLogFunc('较短采集:' + parseInt(restartTime / 1000) + "秒")
        restartTime = new Date().getTime() + restartTime + 5000;
        return restartTime;
    } else if (shibiefangshi == 1) {
        let clip = images.clip(captureScreen(), youshangDuilie.x, youshangDuilie.y, youshangDuilie.w, youshangDuilie.h);
        let result = paddle.ocrText(clip);
        clip.recycle();
        let restartTime = 0;
        for (let index = 0; index < result.length; index++) {
            let element = result[index];
            if (element.includes(':')) {
                let shortest = formatGameTime(element);
                if (restartTime == 0) {
                    restartTime = shortest;
                }
                if (shortest < restartTime && shortest != 0) {
                    myLogFunc('较短采集:' + element)
                    restartTime = shortest;
                }
            }
        }
        restartTime = new Date().getTime() + restartTime + 5000;
        return restartTime;
    } else {
        let clip = images.clip(captureScreen(), youshangDuilie.x, youshangDuilie.y + (20 * picJizhun), youshangDuilie.w, youshangDuilie.h);
        let result = gmlkit.ocr(clip, "zh");
        clip.recycle();
        result = result.text;
        log("时间数据", result)
        result = extractNumbers(result)
        log("时间数据1", result)
        let myLength = parseInt(result.length / 3)
        let restartTime = 0;
        for (let index = 0; index < myLength; index++) {
            let shortest = formatGameTime1(result[index * 3], result[(index * 3) + 1], result[(index * 3) + 2]);
            if (restartTime == 0) {
                restartTime = shortest;
            }
            if (shortest < restartTime && shortest != 0) {
                restartTime = shortest;
            }
        }
        myLogFunc('较短采集:' + parseInt(restartTime / 1000) + "秒")
        restartTime = new Date().getTime() + restartTime + 5000;
        return restartTime;
    }
}

// 扫描野怪
function yeguaisaomiaoFunc(buhui) {
    // 采集任务
    log("最短采集:", new Date().getTime() > zuiduancaiji, zuiduancaiji, new Date().getTime())
    if (Boolean(storage.get("caijiziyuan", true)) && zuiduancaiji != 0 && new Date().getTime() > zuiduancaiji) {
        caijiziyuanFunc()
        sleep(yanchi1)
        zuiduancaiji = zuiduancaijiFunc()
        return;
    }
    // 是不是高频都跳打野 然后检测队列 检测队列就会检测敌袭
    dayechashuFunc()

    log('去打野啊')
    let thisImgs = null;
    let threshold = 0.78;
    let cap = captureScreen();
    let pointsAllList = []
    if (Boolean(storage.get("ye1", false))) {
        if (deviceHeight == 1080) {
            threshold = 0.85;
        } else {
            threshold = 0.83;
        }
        thisImgs = images.read("./res/一级野.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight);
        let thisResult = images.matchTemplate(cap, thisImgs, { threshold: threshold, max: 6 });
        thisImgs.recycle();
        if (thisResult.matches.length) {
            log('thisResult1', thisResult)
            let points = thisResult.sortBy("left-right").points;
            pointsAllList = pointsAllList.concat(points);
            log('pointsAllList1', pointsAllList)
        }
    }
    if (Boolean(storage.get("ye2", false))) {
        if (deviceHeight == 1080) {
            threshold = 0.85;
        } else {
            threshold = 0.84;
        }
        thisImgs = images.read("./res/二级野.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight);
        let thisResult = images.matchTemplate(cap, thisImgs, { threshold: threshold, max: 6 });
        thisImgs.recycle();
        if (thisResult.matches.length) {
            log('thisResult2', thisResult)
            let points = thisResult.sortBy("left-right").points;
            pointsAllList = pointsAllList.concat(points);
            log('pointsAllList2', pointsAllList)
        }
    }
    if (Boolean(storage.get("ye3", false))) {
        threshold = 0.8;
        if (deviceHeight == 1080) {
            threshold = 0.85;
        } else {
            threshold = 0.84;
        }
        thisImgs = images.read("./res/三级野.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight);
        let thisResult = images.matchTemplate(cap, thisImgs, { threshold: threshold, max: 6 });
        thisImgs.recycle();
        if (thisResult.matches.length) {
            log('thisResult3', thisResult)
            let points = thisResult.sortBy("left-right").points;
            pointsAllList = pointsAllList.concat(points);
            log('pointsAllList3', pointsAllList)
        }
    }
    if (Boolean(storage.get("ye4", false))) {
        if (deviceHeight == 1080) {
            threshold = 0.85;
        } else {
            threshold = 0.83;
        }
        thisImgs = images.read("./res/四级野.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight);
        let thisResult = images.matchTemplate(cap, thisImgs, { threshold: threshold, max: 4 });
        thisImgs.recycle();
        if (thisResult.matches.length) {
            log('thisResult4', thisResult)
            let points = thisResult.sortBy("left-right").points;
            pointsAllList = pointsAllList.concat(points);
            log('pointsAllList4', pointsAllList)
        }
    }
    if (Boolean(storage.get("ye5", false))) {
        if (deviceHeight == 1080) {
            threshold = 0.85;
        } else {
            threshold = 0.83;
        }
        thisImgs = images.read("./res/五级野.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight);
        let thisResult = images.matchTemplate(cap, thisImgs, { threshold: threshold, max: 5 });
        thisImgs.recycle();
        if (thisResult.matches.length) {
            log('thisResult5', thisResult)
            let points = thisResult.sortBy("left-right").points;
            pointsAllList = pointsAllList.concat(points);
            log('pointsAllList5', pointsAllList)
        }
    }
    if (Boolean(storage.get("ye6", false))) {
        if (deviceHeight == 1080) {
            threshold = 0.85;
        } else {
            threshold = 0.83;
        }
        thisImgs = images.read("./res/六级野.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight);
        let thisResult = images.matchTemplate(cap, thisImgs, { threshold: threshold, max: 4 });
        thisImgs.recycle();
        if (thisResult.matches.length) {
            log('thisResult6', thisResult)
            let points = thisResult.sortBy("left-right").points;
            pointsAllList = pointsAllList.concat(points);
            log('pointsAllList6', pointsAllList)
        }
    }
    if (Boolean(storage.get("ye7", false))) {
        if (deviceHeight == 1080) {
            threshold = 0.85;
        } else {
            threshold = 0.83;
        }
        thisImgs = images.read("./res/七级野.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight);
        let thisResult = images.matchTemplate(cap, thisImgs, { threshold: threshold, max: 3 });
        thisImgs.recycle();
        if (thisResult.matches.length) {
            log('thisResult7', thisResult)
            let points = thisResult.sortBy("left-right").points;
            pointsAllList = pointsAllList.concat(points);
            log('pointsAllList7', pointsAllList)
        }
    }

    if (!thisImgs) {
        thisImgs = images.read("./res/级野.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight);
        let thisResult = images.matchTemplate(captureScreen(), thisImgs, { threshold: threshold, max: 10 });
        thisImgs.recycle();
        if (thisResult.matches.length) {
            let points = thisResult.sortBy("left-right").points;
            pointsAllList = pointsAllList.concat(points);
            log('pointsAllList_all', pointsAllList)
        }
    }

    log("pointsAllList", pointsAllList)
    if (pointsAllList.length) {
        log('野怪数据', pointsAllList)
        if (pointsAllList.length == 1) {
            dayechashuFunc()
            myLogFunc('单野怪')
            let p = pointsAllList[0];
            if (!dayeClick(p.x, p.y)) {
                return false;
            }
            qudayeaFunc(false)
        } else {
            myLogFunc('多野怪')
            for (let index = 0; index < pointsAllList.length; index++) {
                let match = pointsAllList[index];
                myLogFunc('野怪' + index, match)
                dayechashuFunc()
                sleep(yanchi1)
                if (!dayeClick(match.x, match.y)) {
                    continue;
                }
                // 主城位置野怪 不回去
                if (buhui) {
                    log('不回去')
                    qudayeaFunc(false)
                } else {
                    log('回')
                    qudayeaFunc(true)
                }
            }
        }
    }
}

// 去打野啊
function qudayeaFunc(ds) {
    sleep(yanchi1)
    let captureScreenTT = captureScreen()
    let thisImgs = images.read("./res/讨伐按钮.png");
    thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
    let p = findImage(captureScreenTT, thisImgs, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)], threshold: 0.85 });
    thisImgs.recycle();

    let thisImgsNs = images.read("./res/zhuchengjunbei.png");
    thisImgsNs = images.scale(thisImgsNs, picJizhun, picJizhunHeight)
    let pNs = findImage(captureScreenTT, thisImgsNs, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), deviceHeight], threshold: 0.85 });
    thisImgsNs.recycle();
    if (pNs) {
        myLogFunc('玩家主城')
        sleep(yanchi)
        back();
        sleep(yanchi)
        return false;
    }
    if (p) {
        myLogFunc('选择英雄', p)
        sleep(yanchi)
        click(p.x, p.y);
        sleep(yanchi2)
        // 英雄信息
        let thisImgs4 = images.read("./res/英雄信息.png");
        thisImgs4 = images.scale(thisImgs4, picJizhun, picJizhunHeight)
        let result = images.matchTemplate(captureScreen(), thisImgs4, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)], threshold: 0.8, max: 8 });
        thisImgs4.recycle();
        if (result.matches.length) {
            if (Boolean(storage.get("shuayewushang", false))) {
                // 无伤打野
                let xx = 0 + Number(storage.get("shuayebaoliu", "0"))
                let p4 = result.sortBy("left-right").matches[xx].point;
                sleep(yanchi)
                click(p4.x - 109, p4.y + 168.5)
                sleep(yanchi1)
                // 讨伐出发
                myLogFunc('讨伐出发')
                let thisImgs5 = images.read("./res/讨伐按钮.png");
                thisImgs5 = images.scale(thisImgs5, picJizhun, picJizhunHeight)
                let p5 = findImage(captureScreen(), thisImgs5, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)] });
                thisImgs5.recycle();
                if (p5) {
                    sleep(yanchi)
                    click(p5.x, p5.y);
                    sleep(yanchi2)
                    // 上次位置
                    if (ds) {
                        if (shangciweizhi.x == 0) {
                            let thisImgsS = images.read("./res/上次位置.png");
                            thisImgsS = images.scale(thisImgsS, picJizhun, picJizhunHeight)
                            let pS = findImage(captureScreen(), thisImgsS);
                            thisImgsS.recycle();
                            if (pS) {
                                sleep(yanchi)
                                let newObj = { x: pS.x, y: pS.y };
                                storage.put("shangciweizhi", newObj);
                                shangciweizhi = storage.get("shangciweizhi", { x: 0, y: 0 });
                                click(pS.x, pS.y);
                                sleep(yanchi5)
                            }
                        } else {
                            click(shangciweizhi.x, shangciweizhi.y);
                            sleep(yanchi5)
                        }
                    }
                }
            } else {
                let needHero = false;
                let aa = result.matches.length - 1 - storage.get("shuayebaoliu", "0");
                result.sortBy("right-left").matches.forEach((match, indea) => {
                    if (needHero) {
                        return;
                    }
                    if (indea >= aa) {
                        log('result.matches.length', result.matches.length, indea)
                        log('跳过保留')
                        return;
                    }
                    log('找合适英雄')
                    sleep(yanchi)
                    click(match.point.x - 109, match.point.y + 168.5);
                    sleep(yanchi1)
                    // 战斗力配置
                    // 如果是第一次则配置战斗力
                    if (zhandouliWeizhi.x == 0) {
                        myLogFunc('第一次配置战斗力参数')
                        log(zhandouliWeizhi)
                        sleep(yanchi)
                        let thisImgs1 = images.read("./res/战斗力.png");
                        thisImgs1 = images.scale(thisImgs1, picJizhun, picJizhunHeight)
                        let p1 = findImage(captureScreen(), thisImgs1, { threshold: 0.85 });
                        thisImgs1.recycle();
                        if (p1) {
                            log('战斗力起点坐标', p1)
                            let newObj = { x: p1.x, y: p1.y, w: 500, h: 65 };
                            storage.put("zhandouliPosit", newObj);
                            zhandouliWeizhi = storage.get("zhandouliPosit", { x: 0, y: 0, w: 500, h: 65 });
                        } else {
                            toastLog("战斗力信息异常")
                            exit()
                        }
                    }

                    let clip = images.clip(captureScreen(), zhandouliWeizhi.x, zhandouliWeizhi.y, zhandouliWeizhi.w * picJizhun, zhandouliWeizhi.h);
                    let resultText = "";
                    if (shibiefangshi == 0) {
                        resultText = gmlkit.ocr(clip, "zh");
                        resultText = resultText.text;
                    } else if (shibiefangshi == 1) {
                        resultText = paddle.ocrText(clip);
                        resultText = resultText[0]
                    } else {
                        resultText = gmlkit.ocr(clip, "zh");
                        resultText = resultText.text;
                    }
                    clip.recycle();
                    // 识别容错
                    if (resultText != "") {
                        resultText = resultText.toString();
                        if (parseInt(storage.get("denglufangshi", 0)) == 0) {
                            if (resultText.indexOf("方超强") != -1) {
                                // 讨伐出发
                                myLogFunc('讨伐出发，胜券在握')
                                let thisImgs5 = images.read("./res/讨伐按钮.png");
                                thisImgs5 = images.scale(thisImgs5, picJizhun, picJizhunHeight)
                                let p5 = findImage(captureScreen(), thisImgs5, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)] });
                                thisImgs5.recycle();
                                if (p5) {
                                    sleep(yanchi)
                                    click(p5.x, p5.y);
                                    sleep(yanchi2)
                                    // 上次位置
                                    if (ds) {
                                        if (shangciweizhi.x == 0) {
                                            let thisImgsS = images.read("./res/上次位置.png");
                                            thisImgsS = images.scale(thisImgsS, picJizhun, picJizhunHeight)
                                            let pS = findImage(captureScreen(), thisImgsS);
                                            thisImgsS.recycle();
                                            if (pS) {
                                                sleep(yanchi)
                                                let newObj = { x: pS.x, y: pS.y };
                                                storage.put("shangciweizhi", newObj);
                                                shangciweizhi = storage.get("shangciweizhi", { x: 0, y: 0 });
                                                click(pS.x, pS.y);
                                                sleep(yanchi5)
                                            }
                                        } else {
                                            click(shangciweizhi.x, shangciweizhi.y);
                                            sleep(yanchi5)
                                        }
                                    }
                                }
                                needHero = true;
                            } else {
                                log("战力不足")
                            }
                        } else if (parseInt(storage.get("denglufangshi", 0)) == 1) {
                            if (resultText.indexOf("超强") != -1 || resultText.indexOf("我强") != -1) {
                                myLogFunc('讨伐出发')
                                let thisImgs5 = images.read("./res/讨伐按钮.png");
                                thisImgs5 = images.scale(thisImgs5, picJizhun, picJizhunHeight)
                                let p5 = findImage(captureScreen(), thisImgs5, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)] });
                                thisImgs5.recycle();
                                if (p5) {
                                    sleep(yanchi)
                                    click(p5.x, p5.y);
                                    sleep(yanchi2)
                                    // 上次位置
                                    if (ds) {
                                        if (shangciweizhi.x == 0) {
                                            let thisImgsS = images.read("./res/上次位置.png");
                                            thisImgsS = images.scale(thisImgsS, picJizhun, picJizhunHeight)
                                            let pS = findImage(captureScreen(), thisImgsS);
                                            thisImgsS.recycle();
                                            if (pS) {
                                                sleep(yanchi)
                                                let newObj = { x: pS.x, y: pS.y };
                                                storage.put("shangciweizhi", newObj);
                                                shangciweizhi = storage.get("shangciweizhi", { x: 0, y: 0 });
                                                click(pS.x, pS.y);
                                                sleep(yanchi5)
                                            }
                                        } else {
                                            click(shangciweizhi.x, shangciweizhi.y);
                                            sleep(yanchi5)
                                        }
                                    }
                                }
                                needHero = true;
                            } else {
                                log("战力不足")
                            }
                        } else if (parseInt(storage.get("denglufangshi", 0)) == 2) {
                            if (resultText.indexOf("超强") != -1 || resultText.indexOf("我强") != -1 || resultText.indexOf("稍强") != -1) {
                                myLogFunc('讨伐出发')
                                let thisImgs5 = images.read("./res/讨伐按钮.png");
                                thisImgs5 = images.scale(thisImgs5, picJizhun, picJizhunHeight)
                                let p5 = findImage(captureScreen(), thisImgs5, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)] });
                                thisImgs5.recycle();
                                if (p5) {
                                    sleep(yanchi)
                                    click(p5.x, p5.y);
                                    sleep(yanchi2)
                                    // 上次位置
                                    if (ds) {
                                        if (shangciweizhi.x == 0) {
                                            let thisImgsS = images.read("./res/上次位置.png");
                                            thisImgsS = images.scale(thisImgsS, picJizhun, picJizhunHeight)
                                            let pS = findImage(captureScreen(), thisImgsS);
                                            thisImgsS.recycle();
                                            if (pS) {
                                                sleep(yanchi)
                                                let newObj = { x: pS.x, y: pS.y };
                                                storage.put("shangciweizhi", newObj);
                                                shangciweizhi = storage.get("shangciweizhi", { x: 0, y: 0 });
                                                click(pS.x, pS.y);
                                                sleep(yanchi5)
                                            }
                                        } else {
                                            click(shangciweizhi.x, shangciweizhi.y);
                                            sleep(yanchi5)
                                        }
                                    }
                                }
                                needHero = true;
                            } else {
                                log("战力不足")
                            }
                        } else {
                            if (resultText.indexOf("超强") != -1 || resultText.indexOf("我强") != -1 || resultText.indexOf("稍强") != -1 || resultText.indexOf("胜负") != -1) {
                                myLogFunc('讨伐出发')
                                let thisImgs5 = images.read("./res/讨伐按钮.png");
                                thisImgs5 = images.scale(thisImgs5, picJizhun, picJizhunHeight)
                                let p5 = findImage(captureScreen(), thisImgs5, { region: [0, (deviceHeight / 2), deviceWidth, (deviceHeight / 2)] });
                                thisImgs5.recycle();
                                if (p5) {
                                    sleep(yanchi)
                                    click(p5.x, p5.y);
                                    sleep(yanchi2)
                                    // 上次位置
                                    if (ds) {
                                        if (shangciweizhi.x == 0) {
                                            let thisImgsS = images.read("./res/上次位置.png");
                                            thisImgsS = images.scale(thisImgsS, picJizhun, picJizhunHeight)
                                            let pS = findImage(captureScreen(), thisImgsS);
                                            thisImgsS.recycle();
                                            if (pS) {
                                                sleep(yanchi)
                                                let newObj = { x: pS.x, y: pS.y };
                                                storage.put("shangciweizhi", newObj);
                                                shangciweizhi = storage.get("shangciweizhi", { x: 0, y: 0 });
                                                click(pS.x, pS.y);
                                                sleep(yanchi5)
                                            }
                                        } else {
                                            click(shangciweizhi.x, shangciweizhi.y);
                                            sleep(yanchi5)
                                        }
                                    }
                                }
                                needHero = true;
                            } else {
                                log("战力不足")
                            }
                        }
                    } else {
                        myLogFunc('读取战斗力信息异常')
                    }
                })
                // 没有合适英雄
                if (!needHero) {
                    myLogFunc('没有合适英雄')
                    back();
                    return false;
                }
            }
        }

        let thisImgs3 = images.read("./res/讨伐按钮.png");
        thisImgs3 = images.scale(thisImgs3, picJizhun, picJizhunHeight)
        let p3 = findImage(captureScreen(), thisImgs3);
        thisImgs3.recycle();
        if (p3) {
            sleep(yanchi)
            click(p.x, p.y);
            sleep(yanchi1)
        }
    } else {
        let thisImgs1 = images.read("./res/侦查按钮.png");
        thisImgs1 = images.scale(thisImgs1, picJizhun, picJizhunHeight)
        let p1 = findImage(captureScreen(), thisImgs1, { threshold: 0.85 });
        thisImgs1.recycle();
        if (p1) {
            if (Boolean(storage.get("chihouzhencha", false))) {
                // 侦查流程
                click(p1.x, p1.y);
                sleep(yanchi1)
                let thisImgs5 = images.read("./res/hx_queding.png");
                thisImgs5 = images.scale(thisImgs5, picJizhun, picJizhunHeight)
                let p5 = findImage(captureScreen(), thisImgs5, { threshold: 0.85 });
                thisImgs5.recycle();
                if (p5) {
                    // 如果是第一次则配置战斗力
                    if (xiaohaochihou.x == 0) {
                        myLogFunc('第一次配置斥候参数')
                        sleep(yanchi)
                        let thisImgsP = images.read("./res/xuxiaohaochihou.png");
                        thisImgsP = images.scale(thisImgsP, picJizhun, picJizhunHeight)
                        let pP = findImage(captureScreen(), thisImgsP, { threshold: 0.85 });
                        thisImgsP.recycle();
                        if (pP) {
                            log('斥候起点坐标', pP)
                            let newObj = { x: pP.x, y: pP.y, w: 300, h: 65 };
                            storage.put("xiaohaochihou", newObj);
                            xiaohaochihou = storage.get("xiaohaochihou", { x: 0, y: 0, w: 300, h: 65 });
                        } else {
                            toastLog("斥候信息异常")
                            exit()
                        }
                    }

                    let clip = images.clip(captureScreen(), xiaohaochihou.x, xiaohaochihou.y, xiaohaochihou.w * picJizhun, xiaohaochihou.h);
                    let resultText = "";
                    if (shibiefangshi == 0) {
                        resultText = gmlkit.ocr(clip, "zh");
                        resultText = resultText.text;
                        resultText = parseFloat(resultText.split(':')[1])
                    } else if (shibiefangshi == 1) {
                        resultText = paddle.ocrText(clip);
                        resultText = resultText[0]
                        resultText = parseFloat(resultText.split('：')[1])
                    } else {
                        resultText = gmlkit.ocr(clip, "zh");
                        resultText = resultText.text;
                        resultText = parseFloat(resultText.split(':')[1])
                    }
                    clip.recycle();
                    myLogFunc('确定')
                    click(p5.x, p5.y)
                    // 计算等待时间
                    sleep(resultText * 2000)
                    click(deviceWidth / 2, ((deviceHeight / 2) - 2))
                    qudayeaFunc(ds);
                } else {
                    myLogFunc('斥候不足')
                    let enter = true;
                    while (enter) {
                        let thisImgs = images.read("./res/蓝底关闭.png");
                        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
                        let p = images.matchTemplate(captureScreen(), thisImgs, { region: [(deviceWidth / 2), 0, (deviceWidth / 2), (deviceHeight / 2)], threshold: 0.86 }).leftmost();
                        thisImgs.recycle();
                        if (p) {
                            myLogFunc('关闭')
                            click(p.point.x + 5, p.point.y + 5);
                            sleep(yanchi1)
                        } else {
                            enter = false;
                            sleep(yanchi)
                        }
                    }
                }
            } else {
                myLogFunc('不侦查野怪')
                sleep(yanchi)
                back();
                sleep(yanchi1)
            }
        } else {
            myLogFunc("野怪定位偏差");
            let thisImgs3 = images.read("./res/别人野怪关闭.png");
            thisImgs3 = images.scale(thisImgs3, picJizhun, picJizhunHeight)
            let p3 = findImage(captureScreen(), thisImgs3, { threshold: 0.85 });
            thisImgs3.recycle();
            if (p3) {
                myLogFunc("正在打野");
                sleep(yanchi)
                click(p3.x, p3.y);
                sleep(yanchi1)
                return false;
            } else {
                let thisImgs2 = images.read("./res/世界首页.png");
                thisImgs2 = images.scale(thisImgs2, picJizhun, picJizhunHeight)
                let p2 = findImage(captureScreen(), thisImgs2, { threshold: 0.86 });
                thisImgs2.recycle();
                if (p2) {
                    myLogFunc('世界模式首页啊')
                    return false;
                } else {
                    myLogFunc('未知界面_打野')
                    back();
                    return false;
                }
            }
        }
    }
}
// 跳过还是等待
function dayechashuFunc() {
    // 先看有没有天选
    if (Boolean(storage.get("tianxuan", false))) {
        // 有天选先把能跳的跳了
        let thisImgs = images.read("./res/jinru.png");
        thisImgs = images.scale(thisImgs, picJizhun, picJizhunHeight)
        let myThre = 0.7;
        if (deviceHeight == 1080) {
            myThre = 0.7;
        } else {
            myThre = 0.68;
        }
        let result = images.matchTemplate(captureScreen(), thisImgs, { region: [youshangDuilie.x, youshangDuilie.y, youshangDuilie.w, youshangDuilie.h], threshold: myThre, max: 4 });
        thisImgs.recycle();
        if (result && result.matches.length) {
            let matchRc1 = result.sortBy("left-right").matches;
            for (let index = 0; index < matchRc1.length; index++) {
                log('进入讨伐', matchRc1[index])
                click(matchRc1[index].point.x + 20, matchRc1[index].point.y)
                sleep(yanchi1)
                let thisImgs3 = images.read("./res/立即跳过.png");
                thisImgs3 = images.scale(thisImgs3, picJizhun, picJizhunHeight)
                let p3 = findImage(captureScreen(), thisImgs3);
                thisImgs3.recycle();
                if (p3) {
                    sleep(yanchi)
                    click(p3.x, p3.y);
                    onece = true;
                    dayeduiwu -= 1;
                    sleep(yanchi3)
                }
                sleep(yanchi3)
            }
        }

        // 再次查看有没有空队列
        let timea = dayeduilieFunc(true)
        // 如果都在回城路上
        if (dayeduiwu >= duiwushangxian) {
            // 大于五分钟 就变成一分钟
            if (timea > 300000) {
                timea = 60000
            }
            // 如果时间大于一分钟就是检查要不要练兵
            let lastLbTime = storage.get("shangcilianbing", 0) - new Date().getTime();
            let jiange = Number(storage.get("shibingjg", "30")) * 1000 * 60;
            if (timea > 60000 && Boolean(storage.get("xunliansb", false)) && Boolean(storage.get("tfsxXunlian", false)) && lastLbTime > jiange) {
                // 返回自己主城
                fanhuizhuchengFunc();
                sleep(1000)
                xunlianshibingFunc();
            }
            myLogFunc('等待' + parseInt(timea / 1000) + '秒')
            sleep(timea + 2000)
            dayechashuFunc()
        }
    } else {
        // 没开天选
        let timea = dayeduilieFunc(true)
        if (dayeduiwu >= duiwushangxian) {
            if (timea > 600000) {
                timea = 300000
            }
            myLogFunc('等待' + parseInt(timea / 1000) + '秒')
            sleep(timea + 10000)
            dayechashuFunc()
        }
    }
}

// 格式化双冒号时间
function formatGameTime(params) {
    params = params.trim()
    params = params.replace(/：/g, ":");
    if (!params.includes(':')) {
        return 0;
    }
    params = params.split(":");
    if (params.length != 3) {
        return 0;
    }

    let newTimeSt = (Number(params[0]) * 60 * 60 * 1000 + Number(params[1]) * 60 * 1000 + Number(params[2])) * 1000;
    if (isNaN(newTimeSt)) {
        return 0;
    }
    return newTimeSt;
}

// 格式化处理后时间
function formatGameTime1(params1, params2, params3) {
    let newTimeSt = params1 * 60 * 60 * 1000 + params2 * 60 * 1000 + params3 * 1000;
    return newTimeSt;
}

// 方形区域打野
function fangxingquyuDyFunc() {
    myLogFunc("区域打野")
    let fangxingYe = storage.get("fangxingPing", "108,88,138,108")
    log(fangxingYe)
    fangxingYe = fangxingYe.split(",")
    log(fangxingYe)
    if (fangxingYe.length == 4) {
        myLogFunc("计算区域")
        let x0 = fangxingYe[0]
        let y0 = fangxingYe[1]
        let x1 = fangxingYe[2]
        let y1 = fangxingYe[3]
        let lengthNumX = parseInt((x1 - x0) / 10)
        log(lengthNumX)
        let lengthNumY = parseInt((y1 - y0) / 8)
        log(lengthNumY)
        let quyuDyList = []

        for (let indexY = 0; indexY <= lengthNumY; indexY++) {
            let y = Number(y0) + (indexY * 8)
            for (let index = 0; index <= lengthNumX; index++) {
                let x = Number(x0) + (index * 10)
                quyuDyList.push({ "x": x, "y": y })
            }
        }
        log('quyuDyList', JSON.stringify(quyuDyList))

        for (let index = 0; index < quyuDyList.length; index++) {
            let element = quyuDyList[index];
            log(element)
            sleep(yanchi)
            seeShijieditu()
            sleep(yanchi1)
            goXyFunc(element.x, element.y)
            sleep(yanchi3)
            yeguaisaomiaoFunc()
            sleep(yanchi1)
        }

    } else {
        myLogFunc("区域打野配置错误")
    }
}


// floatyConsole.close();